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

Why contains does not uses @> operator #96

Open
rodo opened this issue Feb 13, 2015 · 6 comments
Open

Why contains does not uses @> operator #96

rodo opened this issue Feb 13, 2015 · 6 comments

Comments

@rodo
Copy link

rodo commented Feb 13, 2015

Hi,

I probably miss something, I'm a end user of django-hstore and just discover that when doing

Cerise.objects.filter(data__contains={'org': 'foo'})

the query executed use the = operator instead of @> that I presume

WHERE ("cerise_cerise"."data"->'soc') = 'breme'

When I would see

WHERE data @> 'soc=>"breme"'::hstore;

If I do not miss anything, will you be open for a path to use @> operator, that is really more efficient with right indexes (not in this obvious case)

@nemesifier
Copy link
Member

hi @rodo, sorry for the delayed answer.

We are open for improvements.

@niwibe @fabiocorneti any thoughts on this?

@assiotis
Copy link

Looking at the code in query.py (verified), this behavior seems to kick in when you are querying on more than one key

@nemesifier
Copy link
Member

Another place to look at is: https://github.com/djangonauts/django-hstore/blob/master/django_hstore/lookups.py

Unfortunately there is some code duplication because for django >= 1.7 the new lookups are used.

@nemesifier
Copy link
Member

BTW @rodo we are open for improvements

@wolever
Copy link

wolever commented Apr 29, 2015

This is a fairly significant issue, as GIN/GiST indexes are only used with @>:

> explain select * from people where fields->'first_name' = 'David'
Seq Scan on people  (cost=0.00..44.84 rows=5 width=113)
  Filter: ((fields -> 'first_name'::text) = 'David'::text)

> explain select * from people where fields @> 'first_name=>David'
Index Scan using people_fields_gist on people  (cost=0.00..8.27 rows=1 width=113)
  Index Cond: (fields @> '"first_name"=>"David"'::hstore)

Ideally there would be syntax which would make the operator (== versus @>) explicit so the query could be tailored to the underlying indexes.

@nemesifier
Copy link
Member

Practical proposals still welcome.

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

No branches or pull requests

4 participants