indexing django hstore virtual fields

54 views
Skip to first unread message

Victor balan

unread,
Oct 11, 2014, 6:23:22 AM10/11/14
to django...@googlegroups.com
Hi,
i have a model like this:
class XXX(models.Model):
   data = hstore.DictionaryField()
   schema = models.TextField()

with a function decode that apply schema to data.
def decode(self):
   self.data.reload_schema(json.decodes(self.schema))

so in my XXX model i have rows with different schemas. How can i index differente fields of schema at db level to speed up queries?


nemesis

unread,
Oct 11, 2014, 6:30:20 AM10/11/14
to django...@googlegroups.com
On Sat, 11 Oct 2014 03:23:22 -0700 (PDT), Victor balan
<balan....@gmail.com> wrote:

[CUT]

> so in my XXX model i have rows with different schemas. How can i
> index differente fields of schema at db level to speed up queries?

Use SQL directly in postgres.

From http://www.postgresql.org/docs/9.1/static/hstore.html:

F.16.3. Indexes

hstore has GiST and GIN index support for the @>, ?, ?& and ?|
operators. For example:

CREATE INDEX hidx ON testhstore USING GIST (h);

CREATE INDEX hidx ON testhstore USING GIN (h);
hstore also supports btree or hash indexes for the = operator. This
allows hstore columns to be declared UNIQUE, or to be used in GROUP BY,
ORDER BY or DISTINCT expressions. The sort ordering for hstore values is
not particularly useful, but these indexes may be useful for equivalence
lookups. Create indexes for = comparisons as follows:

CREATE INDEX hidx ON testhstore USING BTREE (h);

CREATE INDEX hidx ON testhstore USING HASH (h);

Reply all
Reply to author
Forward
0 new messages