pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Artur Zając <azajac@ang.com.pl>
To: pgsql-performance@postgresql.org
Subject: Speed of EXCECUTE in PL/PGSQL
Date: Thu, 14 Mar 2013 20:22:07 +0100
Message-ID: <035b01ce20e9$38ec92a0$aac5b7e0$@ang.com.pl> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-performance>

Hi,

 

I have PostgreSQL 9.0.12 on Windows. 

 

I have some simple function:

 

CREATE OR REPLACE FUNCTION sfunction() RETURNS BOOL AS

$BODY$

DECLARE

q TEXT;

r RECORD;

BEGIN

  q='SELECT 1 from tb_klient LIMIT 0';

 

  FOR r IN EXECUTE q

  LOOP

  END LOOP;

   RETURN NULL;

 

RETURN NULL;

END;

$BODY$

LANGUAGE 'plpgsql';

 

 

And some simple Query:

 

 

explain analyze SELECT sfunction() AS value

FROM (

SELECT 5604913 AS id ,5666 AS idtowmag 

) AS c  

LEFT OUTER JOIN tg_tm AS tm ON (tm.ttm_idtowmag=c.idtowmag);

 

When I run this query explain analyze is:

 

Subquery Scan on a  (cost=0.00..0.27 rows=1 width=8) (actual
time=24.041..24.042 rows=1 loops=1)

  ->  Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.001..0.002
rows=1 loops=1)

"Total runtime: 24.068 ms"

 

But when I change:

1.       Table tb_klient to some other table (but not any other - queries
with some tables are still slow) or

2.       "FOR r IN EXECUTE q"
change to
"FOR r IN SELECT 1 from tb_klient LIMIT 0" or

3.       add "LEFT OUTER JOIN tb_klient AS kl ON
(kl.k_idklienta=c.idtowmag)" to query

 

Explain analyze of query is:

"Subquery Scan on a  (cost=0.00..0.27 rows=1 width=8) (actual
time=1.868..1.869 rows=1 loops=1)"

"  ->  Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.002..0.002
rows=1 loops=1)"

"Total runtime: 1.894 ms"

 

Explain analyze of "SELECT 1 from tb_klient LIMIT 0" is:

 

"Limit  (cost=0.00..0.13 rows=1 width=0) (actual time=0.001..0.001 rows=0
loops=1)"

"  ->  Seq Scan on tb_klient  (cost=0.00..854.23 rows=6823 width=0) (never
executed)"

"Total runtime: 0.025 ms"

 

tb_klient has 8200 rows and 77 cols.

 

Why speed of executing (or planning) some very simple query from string in
pl/pgsql is dependent from whole query or why "FOR r IN EXECUTE q" is
significally slower from "FOR r IN query"?

 

 

-------------------------------------------

Artur Zajac

 

 

view thread (3+ messages)  latest in thread

Message-ID: <035b01ce20e9$38ec92a0$aac5b7e0$@ang.com.pl>
Permalink:  ../035b01ce20e9$38ec92a0$aac5b7e0$@ang.com.pl/
Also on:    postgresql.org/message-id/035b01ce20e9$38ec92a0$aac5b7e0$@ang.com.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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: azajac@ang.com.pl
  Subject: Re: Speed of EXCECUTE in PL/PGSQL
  In-Reply-To: <035b01ce20e9$38ec92a0$aac5b7e0$@ang.com.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