Re: BUG #2953: index scan, feature request - Mailing list pgsql-bugs

From Magnus Hagander
Subject Re: BUG #2953: index scan, feature request
Date
Msg-id 20070202081318.GB20955@svr2.hagander.net
Whole thread Raw
In response to Re: BUG #2953: index scan, feature request  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-bugs
On Thu, Feb 01, 2007 at 09:17:51PM -0500, Tom Lane wrote:
> "michael" <miblogic@yahoo.com> writes:
> > can these be executed with index seek like what MS SQL does?
> > select * from account_category
> > where account_category_full_description <> 'MICHAEL'
>
> What for?  A query like that is generally going to fetch the majority of
> the table, so an indexscan would be counterproductive.
>
> It could potentially be a win if a very large fraction of the rows had
> the exact value MICHAEL ... but the recommended way to deal with that is
> to create a partial index with "full_description <> 'MICHAEL'" as the
> WHERE clause.

Just FYI, the reason that MSSQL does this is most likely that you have a
covering, clustered index on that column. First of all, if you have a
clustered index on that table, SQLServer wil always do an indexscan -
because there is no way to heap-scan such a table. And second, since
SQLServer has covering indexes, they can use indexes in cases where it
returns even a significant portion of the table.

//Magnus

pgsql-bugs by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: BUG #2952: where is the user guide
Next
From: Bruce Momjian
Date:
Subject: Re: "Julian day" date format is off by 12 hours