Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 52f6918

Browse files
committed
Update IN/EXISTS item.
1 parent 5aa7849 commit 52f6918

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

doc/FAQ

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Frequently Asked Questions (FAQ) for PostgreSQL
33

4-
Last updated: Mon Sep 30 23:28:35 EDT 2002
4+
Last updated: Wed Oct 9 23:14:53 EDT 2002
55

66
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
77

@@ -998,18 +998,21 @@ CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
998998
4.22) Why are my subqueries using IN so slow?
999999

10001000
Currently, we join subqueries to outer queries by sequentially
1001-
scanning the result of the subquery for each row of the outer query. A
1002-
workaround is to replace IN with EXISTS:
1001+
scanning the result of the subquery for each row of the outer query.
1002+
If the subquery returns only a few rows and the outer query returns
1003+
many rows, IN is fastest. To speed up other queries, replace IN with
1004+
EXISTS:
10031005
SELECT *
10041006
FROM tab
1005-
WHERE col1 IN (SELECT col2 FROM TAB2)
1007+
WHERE col IN (SELECT subcol FROM subtab)
10061008

10071009
to:
10081010
SELECT *
10091011
FROM tab
1010-
WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)
1012+
WHERE EXISTS (SELECT subcol FROM subtab WHERE subcol = col)
10111013

1012-
We hope to fix this limitation in a future release.
1014+
For this to be fast, subcol should be an indexed column. We hope to
1015+
fix this limitation in a future release.
10131016

10141017
4.23) How do I perform an outer join?
10151018

doc/src/FAQ/FAQ.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
alink="#0000ff">
1515
<H1>Frequently Asked Questions (FAQ) for PostgreSQL</H1>
1616

17-
<P>Last updated: Mon Sep 30 23:28:35 EDT 2002</P>
17+
<P>Last updated: Wed Oct 9 23:14:53 EDT 2002</P>
1818

1919
<P>Current maintainer: Bruce Momjian (<A href=
2020
"mailto:pgman@candle.pha.pa.us">pgman@candle.pha.pa.us</A>)<BR>
@@ -1282,22 +1282,25 @@ <H4><A name="4.22">4.22</A>) Why are my subqueries using
12821282

12831283
<P>Currently, we join subqueries to outer queries by sequentially
12841284
scanning the result of the subquery for each row of the outer
1285-
query. A workaround is to replace <CODE>IN</CODE> with
1285+
query. If the subquery returns only a few rows and the outer query
1286+
returns many rows, <CODE><SMALL>IN</SMALL></CODE> is fastest. To
1287+
speed up other queries, replace <CODE>IN</CODE> with
12861288
<CODE>EXISTS</CODE>:</P>
12871289
<PRE>
12881290
<CODE>SELECT *
12891291
FROM tab
1290-
WHERE col1 IN (SELECT col2 FROM TAB2)
1292+
WHERE col IN (SELECT subcol FROM subtab)
12911293
</CODE>
12921294
</PRE>
12931295
to:
12941296
<PRE>
12951297
<CODE>SELECT *
12961298
FROM tab
1297-
WHERE EXISTS (SELECT col2 FROM TAB2 WHERE col1 = col2)
1299+
WHERE EXISTS (SELECT subcol FROM subtab WHERE subcol = col)
12981300
</CODE>
12991301
</PRE>
13001302

1303+
For this to be fast, <CODE>subcol</CODE> should be an indexed column.
13011304
We hope to fix this limitation in a future release.
13021305

13031306
<H4><A name="4.23">4.23</A>) How do I perform an outer join?</H4>

0 commit comments

Comments
 (0)