%ex1.4

\begin{enumerate}[label=(\alph*)]
\item Hash Join, then Merge Join
\begin{verbatim}
Merge Join  (cost=126688.84..189746.85 rows=4812309 width=12) (actual time=1235.201..3507.532 rows=4790517 loops=1)
  Output: r.a, r.b, s.c
  Merge Cond: ((t.a = r.a) AND (t.c = s.c))
  Buffers: shared hit=138, temp read=1320 written=3593
  ->  Sort  (cost=809.39..834.39 rows=10000 width=8) (actual time=15.180..17.809 rows=10000 loops=1)
        Output: t.a, t.c
        Sort Key: t.a, t.c
        Sort Method: quicksort  Memory: 853kB
        Buffers: shared hit=45
        ->  Seq Scan on public.t  (cost=0.00..145.00 rows=10000 width=8) (actual time=0.036..4.271 rows=10000 loops=1)
              Output: t.a, t.c
              Buffers: shared hit=45
  ->  Materialize  (cost=125878.37..130770.59 rows=978445 width=12) (actual time=1220.009..1810.482 rows=4790518 loops=1)
        Output: r.a, r.b, s.c
        Buffers: shared hit=93, temp read=1320 written=3593
        ->  Sort  (cost=125878.37..128324.48 rows=978445 width=12) (actual time=1220.003..1267.097 rows=105629 loops=1)
              Output: r.a, r.b, s.c
              Sort Key: r.a, s.c
              Sort Method: external merge  Disk: 21312kB
              Buffers: shared hit=93, temp read=1320 written=3593
              ->  Hash Join  (cost=270.00..11799.45 rows=978445 width=12) (actual time=7.133..326.364 rows=993774 loops=1)
                    Output: r.a, r.b, s.c
                    Hash Cond: (r.b = s.b)
                    Buffers: shared hit=93
                    ->  Seq Scan on public.r  (cost=0.00..145.00 rows=10000 width=8) (actual time=0.023..2.157 rows=10000 loops=1)
                          Output: r.a, r.b
                          Buffers: shared hit=45
                    ->  Hash  (cost=145.00..145.00 rows=10000 width=8) (actual time=7.022..7.022 rows=10000 loops=1)
                          Output: s.c, s.b
                          Buckets: 16384  Batches: 1  Memory Usage: 519kB
                          Buffers: shared hit=45
                          ->  Seq Scan on public.s  (cost=0.00..145.00 rows=10000 width=8) (actual time=0.021..3.459 rows=10000 loops=1)
                                Output: s.c, s.b
                                Buffers: shared hit=45
Planning time: 0.899 ms
Execution time: 4040.426 ms

\end{verbatim}

\item

Only Merge join: Total cost: 190481.63
Only Hash join: Total cost: 378418.91
Only Nestloop: Total cost: 174352535.00

\end{enumerate}
