1
1
2
2
Frequently Asked Questions (FAQ) for PostgreSQL
3
3
4
- Last updated: Fri Oct 10 17:27:02 EDT 2003
4
+ Last updated: Wed Oct 29 15:19:43 EST 2003
5
5
6
6
Current maintainer: Bruce Momjian (pgman@candle.pha.pa.us)
7
7
@@ -1031,11 +1031,11 @@ CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
1031
1031
1032
1032
4.22) Why are my subqueries using IN so slow?
1033
1033
1034
- Currently, we join subqueries to outer queries by sequentially
1035
- scanning the result of the subquery for each row of the outer query.
1036
- If the subquery returns only a few rows and the outer query returns
1037
- many rows, IN is fastest. To speed up other queries, replace IN with
1038
- EXISTS:
1034
+ In versions prior to 7.4, subqueries were joined to outer queries by
1035
+ sequentially scanning the result of the subquery for each row of the
1036
+ outer query. If the subquery returns only a few rows and the outer
1037
+ query returns many rows, IN is fastest. To speed up other queries,
1038
+ replace IN with EXISTS:
1039
1039
SELECT *
1040
1040
FROM tab
1041
1041
WHERE col IN (SELECT subcol FROM subtab);
@@ -1045,8 +1045,10 @@ CREATE TABLE test (x int, modtime timestamp DEFAULT CURRENT_TIMESTAMP );
1045
1045
FROM tab
1046
1046
WHERE EXISTS (SELECT subcol FROM subtab WHERE subcol = col);
1047
1047
1048
- For this to be fast, subcol should be an indexed column. This
1049
- preformance problem will be fixed in 7.4.
1048
+ For this to be fast, subcol should be an indexed column.
1049
+
1050
+ In version 7.4 and later, IN actually uses the same sophisticated join
1051
+ techniques as normal queries, and is prefered to using EXISTS.
1050
1052
1051
1053
4.23) How do I perform an outer join?
1052
1054
0 commit comments