pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Performance Problem Index Ignored, but why
5+ messages / 4 participants
[nested] [flat]

* Performance Problem Index Ignored, but why
@ 2002-05-22 02:01  Thomas A. Lowery <tl-lists@stlowery.net>
  0 siblings, 1 reply; 5+ messages in thread

From: Thomas A. Lowery @ 2002-05-22 02:01 UTC (permalink / raw)
  To: pgsql-admin

I've the task of porting a current Oracle application to PostgreSQL.

Database: 7.2.1
OS: Linux 2.4.9-13smp

I've an odd thing happening with a query.  Using a simple table:

            Table "state_tst"
Column  |         Type         | Modifiers
---------+----------------------+-----------
id      | integer              | not null
v_state | character varying(2) |
f_state | character(2)         |
Indexes: st_f_state_idx,
	st_v_state_idx
Primary key: state_tst_pkey

id is a sequence number and primary key, v_state and f_state are 2
character U.S. States.  I created v_state as varchar(2) and f_state as
char(2) to test if the query explained/performed differently (it
doesn't).

CREATE INDEX st_v_state_idx ON state_tst USING btree (v_state);
CREATE INDEX st_f_state_idx ON state_tst USING btree (f_state);

Load the table using a copy from ...

vacuum verbose analyze state_tst;

Total rows: 14309241

Queries using either f_state = or v_state =  explain (and appear to
execute) using a sequential scan.  Resulting in 60 - 80 second query
times.

Can I force the use of an index?  Or do I have something wrong?  Any
ideas?

pg_test=# explain select  count(*) from state_tst where f_state = 'PA';
NOTICE:  QUERY PLAN:

Aggregate  (cost=277899.65..277899.65 rows=1 width=0)
  ->  Seq Scan on state_tst  (cost=0.00..277550.51 rows=139654
  width=0)

EXPLAIN



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Performance Problem Index Ignored, but why
@ 2002-05-22 04:02  Thomas A. Lowery <tlowery@stlowery.net>
  0 siblings, 1 reply; 5+ messages in thread

From: Thomas A. Lowery @ 2002-05-22 04:02 UTC (permalink / raw)
  To: pgsql-admin

I've the task of porting a current Oracle application to PostgreSQL.

Database: 7.2.1
OS: Linux 2.4.9-13smp

I've an odd thing happening with a query.  Using a simple table:

            Table "state_tst"
Column  |         Type         | Modifiers
---------+----------------------+-----------
id      | integer              | not null
v_state | character varying(2) |
f_state | character(2)         |
Indexes: st_f_state_idx,
	st_v_state_idx
Primary key: state_tst_pkey

id is a sequence number and primary key, v_state and f_state are 2
character U.S. States.  I created v_state as varchar(2) and f_state as
char(2) to test if the query explained/performed differently (it
doesn't).

CREATE INDEX st_v_state_idx ON state_tst USING btree (v_state);
CREATE INDEX st_f_state_idx ON state_tst USING btree (f_state);

Load the table using a copy from ...

vacuum verbose analyze state_tst;

Total rows: 14309241

Queries using either f_state = or v_state =  explain (and appear to
execute) using a sequential scan.  Resulting in 60 - 80 second query
times.

Can I force the use of an index?  Or do I have something wrong?  Any
ideas?

pg_test=# explain select  count(*) from state_tst where f_state = 'PA';
NOTICE:  QUERY PLAN:

Aggregate  (cost=277899.65..277899.65 rows=1 width=0)
  ->  Seq Scan on state_tst  (cost=0.00..277550.51 rows=139654
  width=0)

EXPLAIN



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Performance Problem Index Ignored, but why
@ 2002-05-22 04:26  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Thomas A. Lowery <tlowery@stlowery.net>
  0 siblings, 1 reply; 5+ messages in thread

From: Tom Lane @ 2002-05-22 04:26 UTC (permalink / raw)
  To: Thomas A. Lowery <tlowery@stlowery.net>; +Cc: pgsql-admin

"Thomas A. Lowery" <tlowery@stlowery.net> writes:
> Can I force the use of an index?

Try "set enable_seqscan = off".  But on the basis of what you've shown,
it's not obvious that an indexscan will be faster.  Is the planner's
estimate that 139654 rows will match f_state = 'PA' in the right
ballpark?

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Performance Problem Index Ignored, but why
@ 2002-05-22 15:40  Thomas A. Lowery <tlowery@stlowery.net>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 5+ messages in thread

From: Thomas A. Lowery @ 2002-05-22 15:40 UTC (permalink / raw)
  To: pgsql-admin

> estimate that 139654 rows will match f_state = 'PA' in the right
No, 375342 is the actual number.  Using the index does appear slower
(limited testing noted).

explain select count(*) from state_tst where f_state = 'PA'/
NOTICE:  QUERY PLAN:

Aggregate  (cost=277899.65..277899.65 rows=1 width=0)
  ->  Seq Scan on state_tst  (cost=0.00..277550.51 rows=139654
  width=0)

select count(*) from state_tst where f_state = 'PA'/
count
'375342'

Elapsed: 139 wallclock secs

set enable_seqscan = off/

 explain select count(*) from state_tst where f_state = 'PA'/
NOTICE:  QUERY PLAN:

Aggregate  (cost=542303.53..542303.53 rows=1 width=0)
 ->  Index Scan using st_f_state_idx on state_tst
 (cost=0.00..541954.39 rows=139654 width=0)

 select count(*) from state_tst where f_state = 'PA'/
count
'375342'

Elapsed: 222 wallclock secs

Tom

On Wed, May 22, 2002 at 12:26:35AM -0400, Tom Lane wrote:
> "Thomas A. Lowery" <tlowery@stlowery.net> writes:
> > Can I force the use of an index?
> 
> Try "set enable_seqscan = off".  But on the basis of what you've shown,
> it's not obvious that an indexscan will be faster.  Is the planner's
> estimate that 139654 rows will match f_state = 'PA' in the right
> ballpark?
> 
> 			regards, tom lane



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Performance Problem Index Ignored, but why
@ 2002-05-22 17:28  Naomi Walker <nwalker@eldocomp.com>
  parent: Thomas A. Lowery <tl-lists@stlowery.net>
  0 siblings, 0 replies; 5+ messages in thread

From: Naomi Walker @ 2002-05-22 17:28 UTC (permalink / raw)
  To: Thomas A. Lowery <tl-lists@stlowery.net>; pgsql-admin


I'm not sure how well this works in Postgres.  For Informix, we could trick 
the optimizer into using an index with something like:

Select colname from table where colname !=NULL.

Specifically mentioning the column in the query was the trick.  In esql/C, 
there were return parameters that then told you how many rows were found.


>CREATE INDEX st_v_state_idx ON state_tst USING btree (v_state);
>CREATE INDEX st_f_state_idx ON state_tst USING btree (f_state);
>
>Load the table using a copy from ...
>
>vacuum verbose analyze state_tst;
>
>Total rows: 14309241
>
>Queries using either f_state = or v_state =  explain (and appear to
>execute) using a sequential scan.  Resulting in 60 - 80 second query
>times.
>
>Can I force the use of an index?  Or do I have something wrong?  Any




>ideas?
>
>pg_test=# explain select  count(*) from state_tst where f_state = 'PA';
>NOTICE:  QUERY PLAN:
>
>Aggregate  (cost=277899.65..277899.65 rows=1 width=0)
>   ->  Seq Scan on state_tst  (cost=0.00..277550.51 rows=139654
>   width=0)
>
>EXPLAIN
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2002-05-22 17:28 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-05-22 02:01 Performance Problem Index Ignored, but why Thomas A. Lowery <tl-lists@stlowery.net>
2002-05-22 17:28 ` Naomi Walker <nwalker@eldocomp.com>
2002-05-22 04:02 Performance Problem Index Ignored, but why Thomas A. Lowery <tlowery@stlowery.net>
2002-05-22 04:26 ` Tom Lane <tgl@sss.pgh.pa.us>
2002-05-22 15:40   ` Thomas A. Lowery <tlowery@stlowery.net>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox