[GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Reid Thompson
Example: assume a table of 10 columns, three of which are fname, lname, and dob. If an index is created on (fname, lname, dob), will a query that utilizes two of the columns ( select 'data' from table where fname = 'X' and lname = 'Y') utilize the index? thanks, reid

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Alvaro Herrera
On Mon, Sep 12, 2005 at 09:43:57AM -0400, Reid Thompson wrote: Example: assume a table of 10 columns, three of which are fname, lname, and dob. If an index is created on (fname, lname, dob), will a query that utilizes two of the columns ( select 'data' from table where fname = 'X' and lname =

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Reid Thompson
Alvaro Herrera wrote: On Mon, Sep 12, 2005 at 09:43:57AM -0400, Reid Thompson wrote: Example: assume a table of 10 columns, three of which are fname, lname, and dob. If an index is created on (fname, lname, dob), will a query that utilizes two of the columns ( select 'data' from table where

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Michael Fuhr
On Mon, Sep 12, 2005 at 09:43:57AM -0400, Reid Thompson wrote: assume a table of 10 columns, three of which are fname, lname, and dob. If an index is created on (fname, lname, dob), will a query that utilizes two of the columns ( select 'data' from table where fname = 'X' and lname = 'Y')

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Michael Fuhr
On Mon, Sep 12, 2005 at 10:05:36AM -0400, Reid Thompson wrote: Alvaro Herrera wrote: Note that if your example query used the columns (lname, dob), the answer would be no. Why is that? In order to use an index, does the query have to utilize the 'first' element of the index? In released

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Alvaro Herrera
On Mon, Sep 12, 2005 at 10:05:36AM -0400, Reid Thompson wrote: Alvaro Herrera wrote: On Mon, Sep 12, 2005 at 09:43:57AM -0400, Reid Thompson wrote: Example: assume a table of 10 columns, three of which are fname, lname, and dob. If an index is created on (fname, lname, dob), will a query

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Tom Lane
Alvaro Herrera [EMAIL PROTECTED] writes: On Mon, Sep 12, 2005 at 09:43:57AM -0400, Reid Thompson wrote: Example: assume a table of 10 columns, three of which are fname, lname, and dob. If an index is created on (fname, lname, dob), will a query that utilizes two of the columns ( select 'data'

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Tom Lane
Alvaro Herrera [EMAIL PROTECTED] writes: On Mon, Sep 12, 2005 at 10:05:36AM -0400, Reid Thompson wrote: Why is that? In order to use an index, does the query have to utilize the 'first' element of the index? The leftmost part. There's no way to scan an index if you don't know the key. On a

Re: [GENERAL] If an index is based on 3 columns will a query using

2005-09-12 Thread Teodor Sigaev
Greg Stark suggests here: http://archives.postgresql.org/pgsql-hackers/2005-05/msg00966.php that GiST could also be fixed to work with any subset of the index columns, but it hasn't been done yet, unless Teodor and Oleg snuck something in during that last round of GiST work. GiST may work with

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Greg Stark
Tom Lane [EMAIL PROTECTED] writes: Alvaro Herrera [EMAIL PROTECTED] writes: Yes, if it is selective enough. (It _can_ use the index, which does not mean that it _will_ use it.) Note that if your example query used the columns (lname, dob), the answer would be no. Actually, that last

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Tom Lane
Teodor Sigaev [EMAIL PROTECTED] writes: GiST may work with any subset of index columns too. Even in existing code I don't see any problem except NULL in a first column. GiST doesn't store tuples with leading NULL value (gist.c lines 174, 326), so index doesn't contained them. Well,

Re: [GENERAL] If an index is based on 3 columns will a query using two of the columns utilize the index?

2005-09-12 Thread Tom Lane
Greg Stark [EMAIL PROTECTED] writes: Tom Lane [EMAIL PROTECTED] writes: http://archives.postgresql.org/pgsql-committers/2005-06/msg00156.php Did that patch actually implement skip scanning? No, it just removed the planner's arbitrary assumption that the index methods wouldn't cope. Skip