From: Bruce Momjian Date: Thu, 10 Oct 2002 03:15:19 +0000 (+0000) Subject: Update IN/EXISTS item. X-Git-Tag: REL7_3~319 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=52f6918c283ac2a9495aa72e9ae414dffe6cbd74;p=postgresql Update IN/EXISTS item. --- diff --git a/doc/FAQ b/doc/FAQ index b7ccc62b06..e74cf8e30a 100644 --- a/doc/FAQ +++ b/doc/FAQ @@ -1,7 +1,7 @@ Frequently Asked Questions (FAQ) for PostgreSQL - Last updated: Mon Sep 30 23:28:35 EDT 2002 + Last updated: Wed Oct 9 23:14:53 EDT 2002 Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us) @@ -998,18 +998,21 @@ CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP ); 4.22) Why are my subqueries using IN so slow? Currently, we join subqueries to outer queries by sequentially - scanning the result of the subquery for each row of the outer query. A - workaround is to replace IN with EXISTS: + scanning the result of the subquery for each row of the outer query. + If the subquery returns only a few rows and the outer query returns + many rows, IN is fastest. To speed up other queries, replace IN with + EXISTS: SELECT * FROM tab - WHERE col1 IN (SELECT col2 FROM TAB2) + WHERE col IN (SELECT subcol FROM subtab) to: SELECT * FROM tab - WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2) + WHERE EXISTS (SELECT subcol FROM subtab WHERE subcol = col) - We hope to fix this limitation in a future release. + For this to be fast, subcol should be an indexed column. We hope to + fix this limitation in a future release. 4.23) How do I perform an outer join? diff --git a/doc/src/FAQ/FAQ.html b/doc/src/FAQ/FAQ.html index cad83373cf..5458766226 100644 --- a/doc/src/FAQ/FAQ.html +++ b/doc/src/FAQ/FAQ.html @@ -14,7 +14,7 @@ alink="#0000ff">

Frequently Asked Questions (FAQ) for PostgreSQL

-

Last updated: Mon Sep 30 23:28:35 EDT 2002

+

Last updated: Wed Oct 9 23:14:53 EDT 2002

Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
@@ -1282,22 +1282,25 @@ BYTEA bytea variable-length byte array (null-byte safe)

Currently, we join subqueries to outer queries by sequentially scanning the result of the subquery for each row of the outer - query. A workaround is to replace IN with + query. If the subquery returns only a few rows and the outer query + returns many rows, IN is fastest. To + speed up other queries, replace IN with EXISTS:

 SELECT *
     FROM tab
-    WHERE col1 IN (SELECT col2 FROM TAB2)
+    WHERE col IN (SELECT subcol FROM subtab)
 
 
to:
 SELECT *
     FROM tab
-    WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)
+    WHERE EXISTS (SELECT subcol FROM subtab WHERE subcol = col)
 
 
+ For this to be fast, subcol should be an indexed column. We hope to fix this limitation in a future release.

4.23) How do I perform an outer join?