Re: reducing number of ANDs speeds up query

From: "T(dot) E(dot) Lawrence" <t(dot)e(dot)lawrence(at)icloud(dot)com>
To: Eduardo Morras <emorrasg(at)yahoo(dot)es>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: reducing number of ANDs speeds up query
Date: 2013-01-12 11:50:54
Message-ID: C88AB999-E7E6-47E7-8DF5-3ACFBB69C272@icloud.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi and thank you!

On 12.01.2013, at 11:52, Eduardo Morras <emorrasg(at)yahoo(dot)es> wrote:

>> With the last "AND b.value=..." the query is extremely slow (did not wait for it to end, but more than a minute), because the value column is not indexed (contains items longer than 8K).
>
> You can construct your own home made index, add a new column in table b, with the first 8-16 bytes/chars of b.value, use this column on your query and refine to a complete b.value. Don't forget tocCreate an index for it too. You can keep this column updated with a trigger.

Yes, I have been considering this in a slightly different way. value contains short and long values (mixed). Only the short values are queried directly. The long values are queried in a tsearch column or in an external Sphinx Search. So probably I should split the short and long values and then index the short values.

It is nevertheless slightly annoying that I cannot make the query do the value thing last...

> Perhaps you can use a partial index for b.value column, i never used that feature so documentation/others can point you how to do it.

Did not know of them, reading. Thank you!
T.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tony Theodore 2013-01-12 12:47:19 Re: reducing number of ANDs speeds up query
Previous Message T. E. Lawrence 2013-01-12 11:41:32 Re: reducing number of ANDs speeds up query