Re: Sequencial scan over primary keys - Mailing list pgsql-general

From Tom Lane
Subject Re: Sequencial scan over primary keys
Date
Msg-id 11282.973869110@sss.pgh.pa.us
Whole thread Raw
In response to Sequencial scan over primary keys  ("Vilson farias" <vilson.farias@digitro.com.br>)
List pgsql-general
"Vilson farias" <vilson.farias@digitro.com.br> writes:
> sitest=# CREATE TABLE tipo_categoria (
> sitest(#        cod_categoria        smallint NOT NULL,
> sitest(#        descricao            varchar(40),
> sitest(#        CONSTRAINT XPKtipo_categoria PRIMARY KEY (cod_categoria)
> sitest(#
> sitest(# );

> sitest=# explain select * from tipo_categoria where cod_categoria = 1;
> NOTICE:  QUERY PLAN:

> Seq Scan on tipo_categoria  (cost=0.00..22.50 rows=10 width=14)

Try it with
  select * from tipo_categoria where cod_categoria = 1::smallint;

An unadorned literal "1" is an int, not a smallint, and the planner is
not currently very smart about indexing cross-datatype comparisons.

Alternatively, just declare your table with column type int.  Because of
alignment requirements for the varchar column, you're not actually
saving any space by using the smallint declaration anyway.

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: strange behvaviour in join? BUG in 7.02?
Next
From: Tom Lane
Date:
Subject: Re: locales and indexes.