muscleoreo.blogg.se

Postgresql coalesce null to use index
Postgresql coalesce null to use index












postgresql coalesce null to use index

Self.lhs = SearchVector(self.lhs, config=config) If not isinstance(_field, SearchVectorField):

postgresql coalesce null to use index

SearchQuery, SearchVector, SearchVectorExact, SearchVectorFieldĬlass PostgresSimpleLookup(FieldGetDbPrepValueMixin, Lookup): search import SearchVector, SearchVectorExact, SearchVectorField django/contrib/postgres/lookups.py diff -git a/django/contrib/postgres/lookups.py b/django/contrib/postgres/lookups.pyįrom django.db.models import Lookup, Transformįrom django.db.models.lookups import Exact, FieldGetDbPrepValueMixinįrom.

POSTGRESQL COALESCE NULL TO USE INDEX PATCH

To_tsvector('simple', column) plainto_tsquery('simple', 'keyword')Ī patch is provided as a suggestion of how this issue might be fixed.

postgresql coalesce null to use index

This should produce the following more desirable SQL: What seems to be possible, however, is to modify the SQL generation to avoid using coalesce where it can be determined that the operand given to to_tsvector will not yield a null value. Unfortunately, the use of coalesce now blocks any application of an index on the column. To_tsvector('simple', coalesce(column, '')) plainto_tsquery('simple', 'keyword') The resulting SQL generated by Django is then as follows: (search=SearchVector("column", config="simple")).filter(search=SearchQuery("keyword", config="simple")) The Django documentation suggests using an annotation employing a SearchVector as follows: To_tsvector(column) plainto_tsquery('simple', 'keyword') (column_search=SearchQuery("keyword", config="simple")) Introducing a SearchQuery object employing the config parameter. "Only text search functions that specify a configuration name can be used in expression indexes Because the two-argument version of to_tsvector was used in the index above, only a query reference that uses the 2-argument version of to_tsvector with the same configuration name will use that index." However, the PostgreSQL documentation notes that such expressions will be unable to take advantage of indexes created on the column: To_tsvector(column) plainto_tsquery('keyword') When following the PostgreSQL full-text search documentation for Django ( ​), the search lookup.














Postgresql coalesce null to use index