How to remove duplicate subqueries

From: "Andrus" <kobruleht2(at)hot(dot)ee>
To: pgsql-general(at)postgresql(dot)org
Subject: How to remove duplicate subqueries
Date: 2008-09-17 08:12:27
Message-ID: gaqe5n$1nul$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have query

SELECT ...
(
SELECT ... FROM (q1) p1 WHERE ...
UNION ALL
SELECT ... FROM (q1) p2 WHERE ...
) p3
GROUP BY f1,f2,f3

This query contains q1 query twice.
q1 takes long time to execute. PostgreSQL probably will execute it two
times.

How to force PostgreSQL 8.1 to execute q1 only once ?

Andrus.

Browse pgsql-general by date

  From Date Subject
Next Message Andrea Moretto 2008-09-17 08:13:01 Pgpool-II and Slony-I : query lag, sequences and stored procedures need help
Previous Message Simon Riggs 2008-09-17 05:59:29 Re: PITR and base + full backups