Multicolumn Index on OR conditions

Started by Jobover 8 years ago3 messagesgeneral
Jump to latest
#1Job
Job@colliniconsulting.it

Hi,

within a query with two or more conditions with "OR", example:

"where a = 2 or b < 3"

could be useful to speed up the query a multi-column index (a,b) even though the two conditions are in "OR" and not in "AND"?

Thank you!
F

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#2vinny
vinny@xs4all.nl
In reply to: Job (#1)
Re: Multicolumn Index on OR conditions

On 2017-09-19 10:08, Job wrote:

Hi,

within a query with two or more conditions with "OR", example:

"where a = 2 or b < 3"

could be useful to speed up the query a multi-column index (a,b) even
though the two conditions are in "OR" and not in "AND"?

Thank you!
F

Having any kind of index usually better than none because it may prevent
a seqscan,
but an OR probably works faster if you have a separate index on B.

But, EXPLAIN can show you what the database actually does, and give some
indication
of why it thinks it should do it that way.

regards, Vincent.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3legrand legrand
legrand_legrand@hotmail.com
In reply to: Job (#1)
Re: Multicolumn Index on OR conditions

No

You should try with 2 single column indexes and may be rewrite your query
with a Union All syntax

--
Sent from: http://www.postgresql-archive.org/PostgreSQL-general-f1843780.html

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general