Just trying to read first row in table based on index, pg scans and sorts instead?

From: johnmudd <johnbmudd(at)gmail(dot)com>
To: pgsql-novice(at)postgresql(dot)org
Subject: Just trying to read first row in table based on index, pg scans and sorts instead?
Date: 2012-04-19 21:41:35
Message-ID: 1334871695398-5652859.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I populated my table, then added the following index. I want to read the
first row based on this index but it takes 3 seconds to get the result. I
hope there's a way to improve this, possibly take advantage of the index.

Index:
"rx_storenbr_rxnbr_rfnbr_index" UNIQUE, btree (storenbr, rxnbr, rfnbr)

reports=> EXPLAIN ANALYZE SELECT * FROM rx ORDER BY (storenbr,rxnbr,rfnbr)
LIMIT 1;
QUERY PLAN
---------------------------------------------------------------------------------------------------------------------------
Limit (cost=24935.26..24935.27 rows=1 width=828) (actual
time=3179.721..3179.721 rows=1 loops=1)
-> Sort (cost=24935.26..25399.14 rows=185551 width=828) (actual
time=3179.719..3179.719 rows=1 loops=1)
Sort Key: (ROW(storenbr, rxnbr, rfnbr))
Sort Method: top-N heapsort Memory: 18kB
-> Seq Scan on rx (cost=0.00..24007.51 rows=185551 width=828)
(actual time=0.038..1094.316 rows=185551 loops=1)
Total runtime: 3179.986 ms
(6 rows)

reports=>
reports=> select version();
                                              version
                                               
------------------------------------------------------------------------------------------------------
PostgreSQL 9.1.2 on i686-pc-linux-gnu, compiled by gcc (Ubuntu/Linaro
4.4.4-14ubuntu5) 4.4.5, 32-bit
(1 row)

--
View this message in context: http://postgresql.1045698.n5.nabble.com/Just-trying-to-read-first-row-in-table-based-on-index-pg-scans-and-sorts-instead-tp5652859p5652859.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2012-04-19 22:11:44 Re: Just trying to read first row in table based on index, pg scans and sorts instead?
Previous Message raghu ram 2012-04-19 18:12:17 Re: logging pg_dump results in windows 7