pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Mario Weilguni <mweilguni@sime.com>
To: pgsql-general@postgresql.org
Subject: strange query plan
Date: Sun, 8 Apr 2001 10:35:00 +0200
Message-ID: <01040810350000.00637@wotan> (raw)

I've a table containing some sort of logs, the table layout ist:
 Attribute |           Type           |               Modifier
-----------+--------------------------+---------------------------------------
 id        | integer                  | not null default nextval('ids'::text)
 serverid  | integer                  | not null
 ts        | timestamp with time zone | default now()
 log       | character varying(400)   | not null
Indices: i1,
         log_pkey

primary key is id, and there is an additional index on serverid. The table 
contains ~ 1.4 mio of rows, I've used "vacuum analyze".

Now when I type:
explain select min(id)from log;
NOTICE:  QUERY PLAN:

Aggregate  (cost=45702.20..45702.20 rows=1 width=4)
  ->  Seq Scan on log  (cost=0.00..41978.36 rows=1489536 width=4)

I don't understand why the index log_pkey is not used here. I guess it would 
be much cheaper to consult the index to get min(), max(), sum() and avg() 
instead of sequentially scanning ~500MB of data.

Any idea?

Thanks

Best regards,
	Mario Weilguni


-- 
===================================================
 Mario Weilguni                               KPNQwest Austria GmbH
 Senior Engineer Web Solutions                         Nikolaiplatz 4
 tel: +43-316-813824                                8020 graz, austria
 fax: +43-316-813824-26                    http://www.kpnqwest.at
 e-mail: mario.weilguni@kpnqwest.com
===================================================



view thread (2+ messages)  latest in thread

Message-ID: <01040810350000.00637@wotan>
Permalink:  ../01040810350000.00637@wotan/
Also on:    postgresql.org/message-id/01040810350000.00637@wotan

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: mweilguni@sime.com, pgsql-general@postgresql.org
  Subject: Re: strange query plan
  In-Reply-To: <01040810350000.00637@wotan>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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