RE: [GENERAL] Re: Index unused with OR?

From: "Jackson, DeJuan" <djackson(at)cpsgroup(dot)com>
To: Olaf Mittelstaedt <mstaedt(at)va-sigi(dot)va(dot)fh-ulm(dot)de>, pgsql-general(at)postgreSQL(dot)org
Subject: RE: [GENERAL] Re: Index unused with OR?
Date: 1998-05-20 14:45:45
Message-ID: F10BB1FAF801D111829B0060971D839F294887@dal_cps.cpsgroup.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> > Unrelated to the question in hand - you complained about VACUUM not
> > properly updating the stats. It seems to me you should use VACUUM
> ANALYZE
> > for that to happen. Just vacuuming means elimination of old rows no
> longer
> > used.
> >
> > Herouth
>
> Thanks for your hint, the statistics got updated now with VACUUM
> ANALYZE, but indexes aren't used anyway when combining indexed
> columns with OR in the WHERE part:
>
> w=> vacuum;
> VACUUM
> w=> vacuum analyze;
> VACUUM
> w=> explain select * from p where (m=29000) or (m=30000);
> NOTICE: QUERY PLAN:
>
> Seq Scan on p (cost=336.92 size=834 width=10)
>
> EXPLAIN
> w=>
>
> Kind regards,
> Olaf
> --
> Olaf Mittelstaedt - IuK - mittelstaedt(at)fh-ulm(dot)de
> Fachhochschule Ulm Prittwitzstr. 10 89075 Ulm
> Tel.: +49 (0)731-502-8220 Fax: -8270
>
> Tertium non datur.
>
If the indexes are used when you do the select without the OR you could
use a UNION ALL to join the tables. I don't know which would cost less,
the sequential scan or the union time.

select * from p where m=29000
union all
select * from p where m=30000;

Should give you the same results.

Browse pgsql-general by date

  From Date Subject
Next Message Peter Mount 1998-05-20 18:37:42 Re: [GENERAL] About Deleting Large Objects
Previous Message Olaf Mittelstaedt 1998-05-20 13:07:31 Re: Index unused with OR?