Chapter 22. PostgreSQL 内部構造の概要

Table of Contents
問合せのパス
接続の確立
パーサステージ
Postgres の rule システム
プランナ/オプティマイザ
エクゼキュータ

著者: This chapter originally appeared as a part of Simkovics, 1998, Stefan Simkovics' Master's Thesis prepared at Vienna University of Technology under the direction of O.Univ.Prof.Dr. Georg Gottlob and Univ.Ass. Mag. Katrin Seyr.

本章は当初 O.Univ.Prof.Dr. Georg Gottlob と Univ.Ass. Mag. Katrin Seyr の指導のもとに、 Stefan Simkovics がウイーン工科大学における博士論文として提出した もの Simkovics, 1998 の一部分でした。

This chapter gives an overview of the internal structure of the backend of Postgres. After having read the following sections you should have an idea of how a query is processed. Don't expect a detailed description here (I think such a description dealing with all data structures and functions used within Postgres would exceed 1000 pages!). This chapter is intended to help understanding the general control and data flow within the backend from receiving a query to sending the results.

本章では Postgres のバックエンドの内部構造 の概要を説明します。以下の節を読むことで、どのように問合せが処理される のかの概念が理解できると思います。ここでは、詳細な記述を期待し ないでください。 (Postgres における全ての データ構造と機能について記述すると容易に 1000 ページを越えた文書 になってしまいます)。本章は、バックエンドが問合せを受けてから問合せ回答 を返すまでの、一般的な制御とデータの流れに関して読者の理解を深めることを 目的としています。

問合せのパス

Here we give a short overview of the stages a query has to pass in order to obtain a result.

ここでは、問合せが問合せ結果を入手するまでの各ステージについて 簡単に概観します。

  1. A connection from an application program to the Postgres server has to be established. The application program transmits a query to the server and receives the results sent back by the server.

    アプリケーションプログラムと Postgres サーバが接続されている必要が有ります。接続されている状態でアプリ ケーションプログラムは Postgres サーバ に問合せを行い、サーバからの問合せ結果を入手します。

  2. The parser stage checks the query transmitted by the application program (client) for correct syntax and creates a query tree.

    パーサステージ では、アプリケーション プログラム(クライアント)からの問合せに対し、その構文が正しい かどうか解析し 問合せツリー を作成します。

  3. The rewrite system takes the query tree created by the parser stage and looks for any rules (stored in the system catalogs) to apply to the querytree and performs the transformations given in the rule bodies. One application of the rewrite system is given in the realization of views.

    書き換えシステムはパーサステージ で作成された問合せツリーを取り込み、 (システムカタログ に格納されている) 問合せツリー に適用する rule を探し、 rule の本体で与えられている 変換を実行します。書き換えシステムによるアプリケーションの一つ として view が実現しました。

    Whenever a query against a view (i.e. a virtual table) is made, the rewrite system rewrites the user's query to a query that accesses the base tables given in the view definition instead.

    view に対しての問合せ(即ち、仮想テーブル)が 作成された時はいつでも、書き換えシステムはユーザの問合せを, その代わりとして、view の定義 で与えられた 基本テーブル にアクセスする問合せに書き換えます。

  4. The planner/optimizer takes the (rewritten) querytree and creates a queryplan that will be the input to the executor.

    プランナ/オプティマイザ は(書き換えられた)問合せツリーを取得し、 エグゼキュータへの入力である 問合せプランを作成します。

    It does so by first creating all possible paths leading to the same result. For example if there is an index on a relation to be scanned, there are two paths for the scan. One possibility is a simple sequential scan and the other possibility is to use the index. Next the cost for the execution of each plan is estimated and the cheapest plan is chosen and handed back.

    この様にして、同じ問合せ結果を導く可能性の有る全ての パスをまず作成します。 例えば、スキャンされるインデックスがリレーション上にあったとすると、 二つのスキャンパスがあります。一つの可能性としては単純な逐次スキャンで、 もう一つはインデックスを利用することです。次に、それぞれのプランを実行 する時の負荷を調べ、より負荷の少ないプランが選択されて戻されます。

  5. The executor recursively steps through the plan tree and retrieves tuples in the way represented by the plan. The executor makes use of the storage system while scanning relations, performs sorts and joins, evaluates qualifications and finally hands back the tuples derived.

    エクゼキュータは再帰的に プランツリー のステップを繰り返し、プランで示されたタプルを抽出します。 エクゼキュータはリレーションをスキャン中に 記憶システムを使って、 sort 及び join を実行し、 条件を評価し、最終的に抽出された タプルを戻します。

In the following sections we will cover every of the above listed items in more detail to give a better understanding on Postgres's internal control and data structures.

引き続く節では、Postgres の内部制御と データ構造の理解を深めるため、上記の項目についてより深く考察 します。