From: Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
To: pgsql-performance@postgresql.org
Subject: Re: Large querie with several EXISTS which will be often runned
Date: Sat, 28 Jun 2003 15:05:00 +0530
Message-ID: <200306281505.00407.shridhar_daithankar@nospam.persistent.co.in> (raw)
In-Reply-To: <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAATBuXKOMvlkWzD3KJN6FWLMKAAAAQAAAAMZDMAFkAG0K6t6raV9fLGwEAAAAA@baguette.net>
References: <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAATBuXKOMvlkWzD3KJN6FWLMKAAAAQAAAAMZDMAFkAG0K6t6raV9fLGwEAAAAA@baguette.net>
On Saturday 28 June 2003 14:47, Bruno BAGUETTE wrote:
> Do you mean this query ?
>
> SELECT
> products_options_groups.pk_prdoptgrp_id,products_options_groups.prdoptgr
> p_name
> FROM products_options_groups
> WHERE EXISTS
> (
> SELECT *
> FROM products_options_classification
> INNER JOIN products_options ON products_options.pk_prdopt_id =
> products_options_classification.fk_prdopt_id
> WHERE products_options_classification =
> products_options_groups.pk_prdoptgrp_id
> AND products_options.fk_prd_id = [A PRODUCT ID WRITTEN HERE BY
> MY APP]
> )
> ORDER BY products_options_groups.prdoptgrp_name;
You can try
SELECT
products_options_groups.pk_prdoptgrp_id,products_options_groups.prdoptgr
p_name
FROM products_options_groups
WHERE
(
SELECT count(*)
FROM products_options_classification
INNER JOIN products_options ON products_options.pk_prdopt_id =
products_options_classification.fk_prdopt_id
WHERE products_options_classification =
products_options_groups.pk_prdoptgrp_id
AND products_options.fk_prd_id = [A PRODUCT ID WRITTEN HERE BY
MY APP]
)>0
ORDER BY products_options_groups.prdoptgrp_name;
The count(*) trick will make it just another subquery and hopefully any
performance issues with exists/in does not figure. Some of those issues are
fixed in 7.4/CVS head though.
HTH
Shridhar
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: shridhar_daithankar@persistent.co.in
Subject: Re: Large querie with several EXISTS which will be often runned
In-Reply-To: <200306281505.00407.shridhar_daithankar@nospam.persistent.co.in>
References: <!~!UENERkVCMDkAAQACAAAAAAAAAAAAAAAAABgAAAAAAAAATBuXKOMvlkWzD3KJN6FWLMKAAAAQAAAAMZDMAFkAG0K6t6raV9fLGwEAAAAA@baguette.net> <200306281505.00407.shridhar_daithankar@nospam.persistent.co.in>
* 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