Query optimization and indexes

From: felix(at)crowfix(dot)com
To: pgsql-general(at)postgresql(dot)org
Subject: Query optimization and indexes
Date: 2006-08-18 23:19:28
Message-ID: 20060818231928.GA19900@crowfix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Suppose I have an index on 5 columns (A, B, C, D, E).

If my WHERE clause is not in that order, will the optimizer reorder
them as necessary and possible?

WHERE A=1 AND C=3 AND B=2 AND E=5 AND D=4

Obviously it can't reorder them in all cases:

WHERE A=1 AND (C=3 OR B=2) AND (E=5 OR D=4)

If I don't specify columns in the WHERE clause, how much can it use
the index? I think it is smart enough to use beginning columns:

WHERE A=1 AND B=2

How about skipping leading columns?

WHERE B=2

How about skipping intermediate columns?

WHERE A=1 AND C=3

Or both, which is probably the same?

WHERE B=2 AND D=4?

--
... _._. ._ ._. . _._. ._. ___ .__ ._. . .__. ._ .. ._.
Felix Finch: scarecrow repairman & rocket surgeon / felix(at)crowfix(dot)com
GPG = E987 4493 C860 246C 3B1E 6477 7838 76E9 182E 8151 ITAR license #4933
I've found a solution to Fermat's Last Theorem but I see I've run out of room o

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-08-19 00:15:47 Re: Query optimization and indexes
Previous Message Jim Nasby 2006-08-18 23:01:58 Re: PITR Questions