[prev] 51 [next]

EXPLAIN Examples (cont)

Example: Join on a non-indexed attribute

uni=# explain analyze
uni=# select s1.code, s2.code
uni-# from Subjects s1, Subjects s2
uni=# where s1.offeredBy=s2.offeredBy;
                        QUERY PLAN
---------------------------------------------------------------
 Merge Join (cost=4449.13..121322.06 rows=7785262 width=18)
            (actual time=29.787..2377.707 rows=8039979 loops=1)
  Merge Cond: (s1.offeredby = s2.offeredby)
  ->  Sort (cost=2224.57..2271.56 rows=18799 width=13)
           (actual time=14.251..18.703 rows=18570 loops=1)
      Sort Key: s1.offeredby
      Sort Method: external merge  Disk: 472kB
      ->  Seq Scan on subjects s1
              (cost=0.00..889.99 rows=18799 width=13)
              (actual time=0.005..4.542 rows=18799 loops=1)
  ->  Sort (cost=2224.57..2271.56 rows=18799 width=13)
           (actual time=15.532..1100.396 rows=8039980 loops=1)
      Sort Key: s2.offeredby
      Sort Method: external sort  Disk: 552kB
      ->  Seq Scan on subjects s2
              (cost=0.00..889.99 rows=18799 width=13)
              (actual time=0.002..3.579 rows=18799 loops=1)
Total runtime: 2767.1 ms