Re: Strange variable behaviour when using it in limit clause in plpgsql stored procedure

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Sergey Moroz" <smo(at)mgcp(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Strange variable behaviour when using it in limit clause in plpgsql stored procedure
Date: 2007-11-08 15:42:56
Message-ID: 24971.1194536576@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Sergey Moroz" <smo(at)mgcp(dot)com> writes:
> I tested performance of my query with limit clause inside plpgsql procedure.
> 2 slightly different situations:

> 1. Sql with limit clause and literal variable (for example 'select field1
> from table1 limit 100')
> 2. The same sql with limit clause and pgplsql variable (for example 'select
> field1 from table1 limit vilimit'). vilimit defined in declare section.

> At first I compared execution plans. they were absolutely equal!
> But in fact first procedure was 10 times!!!! faster then the second!

Exactly what did you do to conclude that the execution plans were the
same? I would not expect the planner to choose the same plan in these
two cases, at least not if 100 is just a small fraction of the total
estimated query output.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2007-11-08 15:47:43 Re: "Resurrected" data files - problem?
Previous Message Tom Lane 2007-11-08 15:39:06 Re: "Resurrected" data files - problem?