Re: Query organization question

Поиск
Список
Период
Сортировка
От Sam Mason
Тема Re: Query organization question
Дата
Msg-id 20090428084224.GC12225@frubble.xen.chris-lamb.co.uk
обсуждение исходный текст
Ответ на Re: Query organization question  ("Gauthier, Dave" <dave.gauthier@intel.com>)
Список pgsql-general
On Mon, Apr 27, 2009 at 02:15:05PM -0700, Gauthier, Dave wrote:
> The stored procedure calls another recursive stored procedure that
> can take a long time to run, usually about 3-4 seconds.  Not bad for
> a handful of records, but it is now operating on a table with over
> 40,000 records.

The most general solution I can think of would be to set the "cost" of
a function when creating it, have a look at the docs for create[1] or
alter[2] function.

The answer to your other question is that the inner select statement is
normally called a "sub-select".  The way to force the sub-select to be
evaluated first is to put an OFFSET 0 at the end of it, i.e.:

  SELECT a, b
  FROM (
    SELECT a.i AS a, b.i AS b
    FROM foo a, foo b
    OFFSET 0) x
  WHERE a < b;

will force PG to create the complete cross product of "foo" with itself
before trying to apply the outer WHERE clause.  I'd try changing the
cost of the function first as it should cause PG to do the "right thing"
when you use the function in other queries.

--
  Sam  http://samason.me.uk/

 [1] http://www.postgresql.org/docs/current/static/sql-createfunction.html
 [2] http://www.postgresql.org/docs/current/static/sql-alterfunction.html

В списке pgsql-general по дате отправления:

Предыдущее
От: David
Дата:
Сообщение: Re: Sequence Incrementing by 2 insted of 1
Следующее
От: itishree sukla
Дата:
Сообщение: Issue with POSTGIS