Query with Max, Order by is very slow....... - Mailing list pgsql-admin

From Hemapriya
Subject Query with Max, Order by is very slow.......
Date
Msg-id 20040407210354.79531.qmail@web21322.mail.yahoo.com
Whole thread Raw
Responses Re: Query with Max, Order by is very slow.......
Re: Query with Max, Order by is very slow.......
List pgsql-admin
Hi,

we have table having 23 million rows.
This is the table structure.
Table Request:

  Column   |            Type             | Modifiers
-----------+-----------------------------+-----------
 origindb  | character(1)                | not null
 uid       | integer                     | not null
 rtype     | integer                     |
 senderid  | integer                     |
 destaddr  | character varying(15)       |
 opid      | integer                     |
 devmodel  | integer                     |
 ikind     | integer                     |
 itemid    | character varying(10)       |
 tranfk    | integer                     |
 enteredon | timestamp without time zone |
 status    | integer                     |
 accountid | integer                     |
Indexes:
    "request_pkey" primary key, btree (origindb, uid)

I do max Query like this

select max(uid) from request where originDB=1;

it took around 20 min to return the result..  Since
max, count functions do the full table scan, i tried
the workaround given..

select uid from request where originDB=1 order by uid
desc limit 1;

this query runs forever.. i tried even without where
condition..no result..

I'm not able to figure out what could be the reason..
can anybody help?

Thanks in Advance

Regards
Priya


__________________________________
Do you Yahoo!?
Yahoo! Small Business $15K Web Design Giveaway
http://promotions.yahoo.com/design_giveaway/

pgsql-admin by date:

Previous
From: Tom Lane
Date:
Subject: Re: Out of space
Next
From: "Jaime Casanova"
Date:
Subject: [admin] index in pk