PostgreSQL上でのベンチマークをとる準備その2

PostgreSQLのベンチマークをとる準備 - gos-k’s blog

前回に続いてまだまだ準備する。

explainの追加

現状のsxqlにexplainはないので追加した。

GitHub - gos-k/sxql: An SQL generator for Common Lisp.

これをローカルにインストールする。

ros install gos-k/sxql

explainを使ってみる。 まず実行と表示をする関数を定義。

(defun expl (sxql &key silent analyze verbose)
  (multiple-value-bind (sql binds)
      (sxql:explain sxql
                    :analyze analyze
                    :verbose verbose)
    (let ((query (dbi:execute (dbi:prepare *connection*
                                           sql)
                              binds)))
      (unless silent
        (format t "~{~A~%~}" (mapcar #'second
                                     (dbi:fetch-all query)))))))

シンプルなexplainの場合。

(expl (sxql:select ((:count :*))
        (sxql:from :bench1)))
Finalize Aggregate  (cost=17083.42..17083.43 rows=1 width=8)
  ->  Gather  (cost=17083.21..17083.42 rows=2 width=8)
        Workers Planned: 2
        ->  Partial Aggregate  (cost=16083.21..16083.22 rows=1 width=8)
              ->  Parallel Seq Scan on bench1  (cost=0.00..14932.17 rows=460417 width=0)

analyzeとverbose付きのexplainの場合。

(expl (sxql:select ((:count :*))
        (sxql:from :bench1)) 
      :analyze t
      :verbose t)
Finalize Aggregate  (cost=17083.42..17083.43 rows=1 width=8) (actual time=45.873..47.078 rows=1 loops=1)
  Output: count(*)
  ->  Gather  (cost=17083.21..17083.42 rows=2 width=8) (actual time=45.849..47.074 rows=3 loops=1)
        Output: (PARTIAL count(*))
        Workers Planned: 2
        Workers Launched: 2
        ->  Partial Aggregate  (cost=16083.21..16083.22 rows=1 width=8) (actual time=41.888..41.888 rows=1 loops=3)
              Output: PARTIAL count(*)
              Worker 0: actual time=40.133..40.134 rows=1 loops=1
              Worker 1: actual time=40.195..40.195 rows=1 loops=1
              ->  Parallel Seq Scan on public.bench1  (cost=0.00..14932.17 rows=460417 width=0) (actual time=0.034..26.286 rows=368333 loops=3)
                    Worker 0: actual time=0.014..24.814 rows=365940 loops=1
                    Worker 1: actual time=0.014..24.961 rows=366903 loops=1

動いた。