- The earlier part of your proposal seems to focus on allowing postgres users to define more complex indexes that they previously haven't been able to use. Oracle is then highlighted also for allowing functional indexes. I think one of the biggest "why's" of this project is to allow users to define custom indexes. It doesn't matter what kind of index. They get access to the stuff that creates them. That should be highlighted before all else.
- Should the type of index (BTree, Spatial, etc) be an index type in and of itself, or should it be a property of a specific index? My knowledge here is limited, so I'm not sure if there are certain constraints on which kind of indexes can use spatial/btree/partial storage types. If certain index types are very heavily restricted, then it probably makes sense to highlight them (as you've done) as a top level class rather than an attribute of indexes in general. If most indexes can be arranged with different storage types though, it'd probably make more sense to expose that functionality as an attribute of all indexes.
- "Index() subclasses will also have a supports(backend) method which would return True or False depending on whether the backend supports that index type." Backends (operations.py) already supports check_expression_support(self, expression). You can bake index support into these methods from within each backend. Especially helpful for third party backends, as they won't need to monkey patch the index classes. The only issue I can see with reusing check_expression_support is the overhead of all other expressions being checked. I don't think that's a big concern, but it's worth being conscious of.
- "Index classes will take 3 arguments fields, model and name - the later two being optional.". Index classes should accept a list of expressions, not just field names. This will allow trivial support of functional indexes without a specific functional index class. You'll also benefit from existing expression subclasses which process field names as F() expressions. F() expressions may have to be changed (or a new concept introduced) which can resolve the field, but doesn't try to do any joining.
Once the index is added to a model, the model can inject itself into the index, or the schema editor can use the originating model to get data it needs. No need to pass the model into the index type I think. Regarding the name, I'm unsure if I prefer a name=Index() or an Index(name='') approach. It'd be good to see that choice in your proposal with a couple of pros and cons.
1) I don't think it's necessary to have an IndexTogether type. Index('field_a', 'field_b') should be sufficient I think. If it's not sufficient, call out why. I'm also in favour of translating any index_together definitions into appropriate Index types. Then SchemaEditor only needs to work with Index expressions and things remain simpler at the boundary between model definition and migrations.
Of course, this is a great thing to have. But I wonder if we can do
something to prevent pushing non-indexes to the indexes attribute of
Meta. Having Meta.indexes = [CheckTypeConstraint(foo__in=['foo',
'bar'])] doesn't read correctly.
Once the index is added to a model, the model can inject itself into the index, or the schema editor can use the originating model to get data it needs. No need to pass the model into the index type I think. Regarding the name, I'm unsure if I prefer a name=Index() or an Index(name='') approach. It'd be good to see that choice in your proposal with a couple of pros and cons.
Well, since we are defining these indexes in a list (to be stored in Meta.indexes) I would go with the Index(name='') approach.
class MyModel(models.Model):
field1 = models.CharField()1) I don't think it's necessary to have an IndexTogether type. Index('field_a', 'field_b') should be sufficient I think. If it's not sufficient, call out why. I'm also in favour of translating any index_together definitions into appropriate Index types. Then SchemaEditor only needs to work with Index expressions and things remain simpler at the boundary between model definition and migrations.
My major concern was about the syntax. Would Index(['f1', 'f2']) mean two indexes (for each field) or one multi-column index. Here we can do something like Index(['f1', 'f2', ['f3', 'f4']]), each element of the list corresponding to a new index.
Would you be able to support partial indexes as well?
Index(...) would create one index from my perspective. Thus Index('field_a', 'field_b') would do the same as index_together=(('field_a', 'field_b'),) these days.Index(['f1', 'f2', ['f3', 'f4']]) looks way to confusing to me. That would probably be better Index('f1'), Index('f2'), Index('f3', 'f4')
Index(['f1', 'f2']) # multi-column indexing.
Index(['f1'], name='name_idx', type=models.Hash) # single-column hash type indexing.
Since we're talking about index_together, please keep unique_together in mind ;)
What about calling the attribute something like "constraints" similar to how it's done in SQLAlchemy [1]? For now the attribute can just contain a list of Index() instances but that would also lay grounds for supporting check constraints and other related table level options.
--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To post to this group, send email to django-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/CALMtK1Eet%3DzPTKXJJpuRy8b0tWF%2BaA9-QaT%2BzfF%3DGV6wAd3N3g%40mail.gmail.com.
you can't have identical indexes defined in multiple ways with the same names.
Instead of aiming for one huge patch to be merged at the end of the summer, I'd suggest to think about whether you can break up the work in chunks that can be merged incrementally. This should decrease the risk that comes with a huge patch going stale and makes code review much easier.
It's helpful if you can add your other commitments for the summer such as holidays, vacations, etc.
That is a bit too strict; sometimes it does make sense to provide more than
one kind of index on one field. As a trivial example, you may want to support
case-sensitive uniqueness as well as case-insensitive search (say, for user-
names).