バージョンごとのドキュメント一覧

32.1. JITコンパイルとは何か? #

<title>What Is <acronym>JIT</acronym> compilation?</title>

Just-in-Time (<acronym>JIT</acronym>) compilation is the process of turning some form of interpreted program evaluation into a native program, and doing so at run time. For example, instead of using general-purpose code that can evaluate arbitrary SQL expressions to evaluate a particular SQL predicate like <literal>WHERE a.col = 3</literal>, it is possible to generate a function that is specific to that expression and can be natively executed by the CPU, yielding a speedup. 実行時(JIT)コンパイルとは、ある形式のインタプリタプログラムの評価をネイティブプログラムに変換する過程であり、かつそれを実行時に行うことを指します。 たとえば、WHERE a.col = 3のような特定のSQL述語を評価するために、任意のSQL式を評価できる汎用目的のコードを使う代わりに、その式専用の関数を生成し、CPUによってネイティブに実行して速度向上をもたらすことができます。

<productname>PostgreSQL</productname> has builtin support to perform <acronym>JIT</acronym> compilation using <ulink url="https://llvm.org/"><productname>LLVM</productname></ulink> when <productname>PostgreSQL</productname> is built with <link linkend="configure-with-llvm"><literal>&#45;-with-llvm</literal></link>. PostgreSQL--with-llvmでビルドされている場合、PostgreSQLにはLLVMを使ってJITコンパイルを実行するためのサポートが組み込まれます。

See <filename>src/backend/jit/README</filename> for further details. さらなる詳細はsrc/backend/jit/READMEをご覧ください。

32.1.1. JITにより高速化される処理 #

<title><acronym>JIT</acronym> Accelerated Operations</title>

Currently <productname>PostgreSQL</productname>'s <acronym>JIT</acronym> implementation has support for accelerating expression evaluation and tuple deforming. Several other operations could be accelerated in the future. 今の所、PostgreSQLJIT実装は、式評価とタプルデフォーミング(tuple deforming)の高速化をサポートしています。 将来は他の操作も高速化されるかも知れません。

Expression evaluation is used to evaluate <literal>WHERE</literal> clauses, target lists, aggregates and projections. It can be accelerated by generating code specific to each case. 式評価は、WHERE句、ターゲットリスト、集約、射影を評価するために使用されます。 それぞれのケースに応じたコードを生成することによって高速化することができます。

Tuple deforming is the process of transforming an on-disk tuple (see <xref linkend="storage-tuple-layout"/>) into its in-memory representation. It can be accelerated by creating a function specific to the table layout and the number of columns to be extracted. タプルデフォーミングは、ディスク上のタプル(73.6.1参照)をメモリ上の表現に変換する処理です。 これはテーブルレイアウトと抽出するカラム数に特化した関数を作ることによって高速化可能です。

32.1.2. インライン展開(Inlining) #

<title>Inlining</title>

<productname>PostgreSQL</productname> is very extensible and allows new data types, functions, operators and other database objects to be defined; see <xref linkend="extend"/>. In fact the built-in objects are implemented using nearly the same mechanisms. This extensibility implies some overhead, for example due to function calls (see <xref linkend="xfunc"/>). To reduce that overhead, <acronym>JIT</acronym> compilation can inline the bodies of small functions into the expressions using them. That allows a significant percentage of the overhead to be optimized away. PostgreSQLは拡張性が高く、新しいデータ型、関数、演算子、その他のデータベースオブジェクトを定義することが可能です。 第38章を参照してください。 実際、組み込みオブジェクトは似た機構を使って実装されています。 この拡張性は、たとえば関数呼び出し(38.3参照)により、幾分のオーバーヘッドをもたらします。 このオーバーヘッドを軽減するために、JITコンパイルは、小さな関数の本体をそれを使っている式にインライン展開することができます。 これにより、オーバーヘッドのかなりの部分を最適化によって解消することができます。

32.1.3. 最適化 #

<title>Optimization</title>

<productname>LLVM</productname> has support for optimizing generated code. Some of the optimizations are cheap enough to be performed whenever <acronym>JIT</acronym> is used, while others are only beneficial for longer-running queries. See <ulink url="https://llvm.org/docs/Passes.html#transform-passes"/> for more details about optimizations. LLVMは、生成したコードの最適化をサポートしています。 ある最適化はJITが使用される際に常に適用できるほど安価ですが、長時間実行する問い合わせのときだけ有利になるようなものもあります。 最適化についてのさらなる詳細は、https://llvm.org/docs/Passes.html#transform-passesをご覧ください。