Re: Similar tables, different indexes performance

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Alvaro Nunes Melo <al_nunes(at)atua(dot)com(dot)br>
Cc: Pgsql-Performance <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Similar tables, different indexes performance
Date: 2004-12-14 05:22:50
Message-ID: 20041214052250.GA8082@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance pgsql-sql

On Mon, Dec 13, 2004 at 17:32:02 -0200,
Alvaro Nunes Melo <al_nunes(at)atua(dot)com(dot)br> wrote:
> Em Seg, 2004-12-13 às 16:03, Bruno Wolff III escreveu:
> > On Mon, Dec 13, 2004 at 15:17:49 -0200,
> > Alvaro Nunes Melo <al_nunes(at)atua(dot)com(dot)br> wrote:
> > > db=> SELECT COUNT(*) FROM titulo WHERE cd_pessoa = 1;
> > > count
> > > -------
> > > 220
> > > (1 record)
> > >
> > > Time: 48,762 ms
> > > db=> SELECT COUNT(*) FROM movimento WHERE cd_pessoa = 1;
> > > count
> > > -------
> > > 221
> > > (1 record)
> > >
> > > Time: 1158,463 ms
> >
> > I suspect you have a lot of dead tuples in those tables.
> > Have you vacuumed them recently?
> > Was there enough FSM space when you did so?
> >
> > You might try doing VACUUM FULL on each table now and see if that
> > fixes the problem.
> The table had not too many tuples delete, but I runned a VACUUM FULL
> VERBOSE ANALYZE and the query's cost and execution time are stil the
> same. The output was:
> INFO: vacuuming "public.movimento"
> INFO: "movimento": found 13 removable, 347355 nonremovable row versions
> in 3251 pages

If the table really has 300K rows, then something else is wrong. One likely
candidate is if cd_pessoa is int8 there is a quirk in postgres (which is
fixed in 8.0) where comparing that column to an int4 constant won't use
an index scan. This can be worked around by either casting the constant
(e.g. 1::int8) or quoting it (e.g. '1') to delay fixing the type so that
it will be taken to be an int8 constant.

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Joe Conway 2004-12-14 06:59:37 Re: Trying to create multi db query in one large querie
Previous Message Spiegelberg, Greg 2004-12-14 04:07:27 Re: Trying to create multi db query in one large querie

Browse pgsql-sql by date

  From Date Subject
Next Message Josh Berkus 2004-12-15 02:29:57 Re: Indexing Strategy
Previous Message Alvaro Nunes Melo 2004-12-13 19:32:02 Re: Similar tables, different indexes performance