Re: Similar tables, different indexes performance - Mailing list pgsql-performance

From Bruno Wolff III
Subject Re: Similar tables, different indexes performance
Date
Msg-id 20041214052250.GA8082@wolff.to
Whole thread Raw
In response to Re: Similar tables, different indexes performance  (Alvaro Nunes Melo <al_nunes@atua.com.br>)
List pgsql-performance
On Mon, Dec 13, 2004 at 17:32:02 -0200,
  Alvaro Nunes Melo <al_nunes@atua.com.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@atua.com.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.

pgsql-performance by date:

Previous
From: "Iain"
Date:
Subject: Re: pg_restore taking 4 hours!
Next
From: "Spiegelberg, Greg"
Date:
Subject: Re: Trying to create multi db query in one large querie