pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: biuro@globeinphotos.com
To: pgsql-performance@postgresql.org
Subject: Curson prbolem
Date: Tue, 20 Jun 2006 14:39:32 +0200
Message-ID: <20060620143932.e7u8gr5s53i808ss@gdn.superhost.pl> (raw)

Hi
I have following table:
CREATE TABLE  alias (
       alias_id           BIGSERIAL PRIMARY KEY,
       mask                      VARCHAR(20) NOT NULL DEFAULT '',
);

with index:
CREATE INDEX alias_mask_ind ON alias(mask);


and this table has about 1 million rows.


In DB procedure I execute:
    LOOP
       <........>
        OPEN cursor1 FOR SELECT * FROM alias WHERE mask>=alias_out
ORDER BY mask;
        i:=0;
        LOOP
           i:=i+1;
             FETCH cursor1 INTO alias_row;
           EXIT WHEN i=10;
        END LOOP;
      CLOSE cursor1;
     EXIT WHEN end_number=10000;
    END LOOP;


Such construction is very slow (20 sec. per one iteration) but when I modify SQL
to:
        OPEN cursor1 FOR SELECT * FROM alias WHERE mask>=alias_out
ORDER BY mask LIMIT 100;


it works very fast(whole program executes in 4-7s). It is strange for me becuase
I've understood so far
that when cursor is open select is executed but Postgres does not
select all rows - only cursor is positioned on first row, when you
execute fetch next row is read. But this example shows something
different.


Can somebody clarify what is wrong with my example? I need select
without LIMIT 100 part.


Regards
Michal Szymanski
http://blog.szymanskich.net






view thread (2+ messages)  latest in thread

Message-ID: <20060620143932.e7u8gr5s53i808ss@gdn.superhost.pl>
Permalink:  ../20060620143932.e7u8gr5s53i808ss@gdn.superhost.pl/
Also on:    postgresql.org/message-id/20060620143932.e7u8gr5s53i808ss@gdn.superhost.pl

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: biuro@globeinphotos.com
  Subject: Re: Curson prbolem
  In-Reply-To: <20060620143932.e7u8gr5s53i808ss@gdn.superhost.pl>
  References: <20060620143932.e7u8gr5s53i808ss@gdn.superhost.pl>

* 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