Subject | Re: [firebird-support] not null and index usage |
---|---|
Author | Ann Harrison |
Post date | 2012-02-13T23:43:57Z |
On Mon, Feb 13, 2012 at 5:09 PM, Sergio H. Gonzalez
<shg_sistemas@...> wrote:
select * from my_table where field1 = 123
uses an index.
select * from my_table where field1 <> 123
does not. The assumption is that there are more records that don't
have a field equal to 123 than there are records that do.
Similarly, the assumption is that there are more records with a not
null field than record with the field value null. There's a
cross-over point where its cheaper to read the whole table than muck
with the index.
Good luck,
Ann
<shg_sistemas@...> wrote:
>Right.
> select * from my_table where (some_id is null)
>
> uses the index... but
>
> select * from my_table where (some_id is not null)
select * from my_table where field1 = 123
uses an index.
select * from my_table where field1 <> 123
does not. The assumption is that there are more records that don't
have a field equal to 123 than there are records that do.
Similarly, the assumption is that there are more records with a not
null field than record with the field value null. There's a
cross-over point where its cheaper to read the whole table than muck
with the index.
Good luck,
Ann