0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PostgreSQLのJITが有効になっているかを確認する方法

Posted at

PostgreSQLのJITがConfigで有効になっているかを確認するには、以下のようにSHOW jitコマンドを使用します。

$ psql
psql (15.7)
Type "help" for help.

ap2=# SHOW jit;
 jit
-----
 on
(1 row)

jit列がonになっていればConfigで有効になっています。しかし、Configで有効にしていても、llvmjitがインストールされていない場合、JITは動作しません。llvmjitがインストールされていない状態でも、SHOW jitはonと表示されます。

以下は、llvmjitがインストールされていない状態でのSHOW jitコマンドの実行結果です。

 sudo dnf remove postgresql15-llvmjit
中略
$ sudo systemctl restart postgresql-15
$ psql
psql (15.7)
Type "help" for help.

ap2=#  SHOW jit;
 jit
-----
 on
(1 row)

JITが実際に機能しているかを確認するには、実際にJITが動作しているかを確認するしかないと思います(他に方法があれば教えていただきたいです)。具体的には、JITに関するパラメータを変更してJITが動作する閾値を下げ、クエリを実行します。

$ psql
psql (15.7)
Type "help" for help.

ap2=# SHOW jit;
 jit
-----
 on
(1 row)

ap2=# SET jit_above_cost=10;
SET
ap2=# SET jit_inline_above_cost=10;
SET
ap2=# SET jit_optimize_above_cost=10;
SET
ap2=# select count(*) from userreview;
  count
---------
 1926960
(1 row)

ap2=# explain select count(*) from userreview;
                                          QUERY PLAN
----------------------------------------------------------------------------------------------
 Finalize Aggregate  (cost=81522.53..81522.54 rows=1 width=8)
   ->  Gather  (cost=81522.31..81522.52 rows=2 width=8)
         Workers Planned: 2
         ->  Partial Aggregate  (cost=80522.31..80522.32 rows=1 width=8)
               ->  Parallel Seq Scan on userreview  (cost=0.00..78522.25 rows=800025 width=0)
 JIT:
   Functions: 4
   Options: Inlining true, Optimization true, Expressions true, Deforming true
(8 rows)

QUERY PLANにJITが表示されていることを確認します。
ちなみに、llvmjitがインストールされていない環境では以下のようになります。

$ sudo dnf remove postgresql15-llvmjit
中略
$ sudo systemctl restart postgresql-15

$ psql
psql (15.7)
Type "help" for help.

ap2=# SET jit_above_cost=10;
SET
ap2=# SET jit_inline_above_cost=10;
SET
ap2=# SET jit_optimize_above_cost=10;
SET
ap2=# select count(*) from userreview;
  count
---------
 1926960
(1 row)

ap2=# explain select count(*) from userreview;
                                          QUERY PLAN
----------------------------------------------------------------------------------------------
 Finalize Aggregate  (cost=81522.53..81522.54 rows=1 width=8)
   ->  Gather  (cost=81522.31..81522.52 rows=2 width=8)
         Workers Planned: 2
         ->  Partial Aggregate  (cost=80522.31..80522.32 rows=1 width=8)
               ->  Parallel Seq Scan on userreview  (cost=0.00..78522.25 rows=800025 width=0)
(5 rows)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?