Kouhei Sutou
null+****@clear*****
Fri Nov 18 17:48:56 JST 2016
Kouhei Sutou 2016-11-18 17:48:56 +0900 (Fri, 18 Nov 2016) New Revision: c6cfe39d68404444aef04aff59fba61b1dd4882e https://github.com/pgroonga/pgroonga.github.io/commit/c6cfe39d68404444aef04aff59fba61b1dd4882e Message: Translate Added files: _po/ja/reference/pgroonga-versus-textsearch-and-pg-trgm.po ja/reference/pgroonga-versus-textsearch-and-pg-trgm.md Modified files: reference/pgroonga-versus-textsearch-and-pg-trgm.md Added: _po/ja/reference/pgroonga-versus-textsearch-and-pg-trgm.po (+544 -0) 100644 =================================================================== --- /dev/null +++ _po/ja/reference/pgroonga-versus-textsearch-and-pg-trgm.po 2016-11-18 17:48:56 +0900 (7502ccc) @@ -0,0 +1,544 @@ +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"PO-Revision-Date: 2016-11-18 17:48+0900\n" +"Language: ja\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=1; plural=0;\n" + +msgid "" +"---\n" +"title: PGroonga versus textsearch and pg_trgm\n" +"---" +msgstr "" +"---\n" +"title: PGroonga対textsearch対pg_trgm\n" +"---" + +msgid "# PGroonga versus textsearch and pg\\_trgm" +msgstr "# PGroonga対textsearch対pg\\_trgm" + +msgid "" +"PostgreSQL provides two full text search modules. They are [textsearch]({{ sit" +"e.postgresql_doc_base_url.en }}/textsearch.html) and [pg\\_trgm]({{ site.postgr" +"esql_doc_base_url.en }}/pgtrgm.html)." +msgstr "" +"PostgreSQLは2つの全文検索モジュールを提供しています。[textsearch]({{ site.postgresql_doc_base_url.j" +"a }}/textsearch.html)と[pg\\_trgm]({{ site.postgresql_doc_base_url.ja }}/pgtrgm." +"html)です。" + +msgid "" +"The textsearch module is a built-in full text search feature. It supports GiST" +" and GIN indexes. If you use GiST or GIN index, you can improve full text sear" +"ch performance." +msgstr "" +"textsearchモジュールはPostgreSQL組み込みの全文検索機能です。GiSTインデックスとGINインデックスをサポートしています。GiSTインデ" +"ックスまたはGINインデックスを使うと全文検索性能を高めることができます。" + +msgid "" +"The pg\\_trgm module is a contrib module. pg\\_trgm provides full text search fe" +"ature. pg\\_trgm also supports GiST and GIN indexes. If you use GiST or GIN ind" +"ex, you can improve full text search performance." +msgstr "" +"pg\\_trgmモジュールはcontribモジュールです。pg\\_trgmは全文検索機能を提供します。pg\\_trgmもGiSTインデックスとGINインデッ" +"クスをサポートしています。GiSTインデックスまたはGINインデックスを使うと全文検索機能を高めることができます。" + +msgid "" +"This documents describes about difference between PGroonga, textsearch and pg\\" +"_trgm." +msgstr "このドキュメントはPGroongaとtextsearchとpg\\_trgmの違いを説明します。" + +msgid "## Characteristics" +msgstr "## 特徴" + +msgid "Here are characteristics of each modules." +msgstr "各モジュールの特徴は次の通りです。" + +msgid "### PGroonga {#pgroonga}" +msgstr "" + +msgid "" +"PGroonga implements both language specific full text search and not language s" +"pecific full text search. PGroonga uses not language specific full text search" +" by default. Normally, PGroonga provides satisfactory full text search result " +"by default." +msgstr "" +"PGroongaは言語に特化した全文検索も言語に依存しない全文検索もどちらもサポートしています。PGroongaはデフォルトでは言語に依存しない全文検索を使" +"います。通常、PGroongaはデフォルトで十分満足のいく全文検索結果を返します。" + +msgid "" +"PGroonga supports all languages by default because PGroonga uses not language " +"specific full text search by default. You don't need to change source code." +msgstr "PGroongaはデフォルトで言語に依存しない全文検索を使うので、デフォルトですべての言語をサポートしています。ソースコードを変更する必要はありません。" + +msgid "PGroonga is fast for searching because it doesn't need \"recheck\"." +msgstr "「recheck」する必要がないのでPGroongaの検索は高速です。" + +msgid "" +"PGroonga is also fast for searching while updating because it doesn't block se" +"arching while updating. PGroonga doesn't decrease search performance while upd" +"ating." +msgstr "PGroongaは更新中の検索をブロックしないので更新中も高速に検索できます。PGroongaは更新中も検索性能を落としません。" + +msgid "PGroonga is also fast for updating." +msgstr "PGroongaは更新も高速です。" + +msgid "" +"PGroonga index is large because it keeps index target text that is already sto" +"red in PostgreSQL." +msgstr "PGroongaはPostgreSQLに保存しているインデックス対象のテキストも保存しているのでインデックスサイズは大きいです。" + +msgid "### The textsearch module {#textsearch}" +msgstr "### textsearchモジュール {#textsearch}" + +msgid "" +"The textsearch module implements language specific full text search. For examp" +"le, English terms are stemmed. All of \"work\", \"works\" and \"worked\" are convert" +"ed to \"work\". It'll improve [recall](https://en.wikipedia.org/wiki/Full-text_s" +"earch#The_precision_vs._recall_tradeoff)." +msgstr "" +"textsearchモジュールは言語に特化した全文検索を実装しています。英語の単語はステミングされます。「work」も「works」も「worked」もすべ" +"て「work」に変換します。ステミングは[再現率](https://ja.wikipedia.org/wiki/%E6%83%85%E5%A0%B1%E6%" +"A4%9C%E7%B4%A2#.E6.A4.9C.E7.B4.A2.E6.80.A7.E8.83.BD.E3.81.AE.E8.A9.95.E4.BE.A1" +")を高めます。" + +msgid "" +"Language specific full text search may improve full text search feature but \"l" +"anguage specific\" means someone implements \"language specific\" process. Postgr" +"eSQL 9.6.1 supports 15 languages such as English, French and Russian but other" +" many languages aren't supported such as Asian languages including Japanese, C" +"hinese and Korean." +msgstr "" +"言語に特価した全文検索はよりよい全文検索機能になるかもしれません。しかし、「言語に特化」しているということはだれかが「言語に特化」した処理をじっそうしなけれ" +"ばいけないということです。PostgreSQL 9.6.1は英語やフランス語やロシア語と言った15の言語をサポートしています。しかし、日本語や中国語、韓国語" +"を含むアジアの言語など多くの言語は未対応です。" + +msgid "" +"The textsearch module is fast for searching because it doesn't need \"recheck\"." +" (If you use weight, you need \"recheck\".)" +msgstr "textsearchモジュールは「recheck」する必要がないので検索は高速です。(重み機能を使う場合は「recheck」が必要です。)" + +msgid "" +"The textsearch module can't process very large text. `1MiB - 1B` is the max by" +"tes of text. If you put 1MiB or more text, you will get the following error:" +msgstr "" +"textsearchモジュールは大きなテキストを扱うことができません。テキストの最大バイト数は`1MiB - 1B`です。1MiB以上のテキストを追加した場" +"合は次のエラーが発生します。" + +msgid "" +"```text\n" +"string is too long for tsvector (XXX bytes, max 1048575 bytes)\n" +"```" +msgstr "" + +msgid "### The pg\\_trgm module {#pg-trgm}" +msgstr "### pg\\_trgmモジュール {#pg-trgm}" + +msgid "" +"The pg\\_trgm module implements not language specific full text search. But pg\\" +"_trgm disables non ASCII characters support. It means that pg\\_trgm doesn't su" +"pport many Asian languages such as Japanese and Chinese by default. You need t" +"o comment out the following line in `contrib/pg_trgm/trgm.h` to enable non ASC" +"II characters support:" +msgstr "" +"pg\\_trgmモジュールは言語に依存しない全文検索を実装しています。しかし、pg\\_trgmはASCII以外の文字のサポートが無効になっています。つまり、" +"デフォルトでは日本語や中国語といったアジアの言語はサポートしていないということです。ASCII以外の言語もサポートするには`contrib/pg_trgm/" +"trgm.h`内の次の行をコメントアウトする必要があります。" + +msgid "" +"```c\n" +"#define KEEPONLYALNUM\n" +"```" +msgstr "" + +msgid "" +"If you're using Debian based system, you can enable non ASCII characters suppo" +"rt without changing pg\\_trgm source code by using `C.UTF-8` locale." +msgstr "" +"Debianベースのシステムを使っている場合は`C.UTF-8`ロケールを使うことでpg\\_trgmのソースコードを変更しなくても非ASCII文字サポートを" +"有効にできます。" + +msgid "" +"The pg\\_trgm module is slow when many documents are matched and each document " +"is long. Because pg\\_trgm need \"recheck\" after index search." +msgstr "" +"pg\\_trgmモジュールは大量のドキュメントがマッチして各ドキュメントが長い場合は遅いです。なぜならpg\\_trgmはインデックスを使った検索のあとに「r" +"echeck」する必要があるからです。" + +msgid "### Summary {#summary}" +msgstr "### 概要 {#summary}" + +msgid "" +"Module | Supported languages | Search | Update | S" +"ize\n" +"---------- | ------------------------------------ | ------- | ------------ | -" +"------\n" +"PGroonga | All | Faster | Faster | L" +"arger\n" +"textsearch | 15 (Asian languages aren't included) | Faster | More slower | S" +"maller\n" +"pg\\_trgm | ASCII only languages | Slower | Slower | S" +"maller" +msgstr "" +"モジュール | サポートしている言語 | 検索 | 更新 | インデックスサイズ\n" +"---------- | ------------------------------------ | ------- | ------------ | -" +"------\n" +"PGroonga | 全言語 | 速い | 速い | 大きい\n" +"textsearch | 15(アジアの言語は未サポート) | 速い | とても遅い | 小さい\n" +"pg\\_trgm | ASCIIのみの言語 | 遅い | 遅い | 小さい" + +msgid "## Benchmark {#benchmark}" +msgstr "## ベンチマーク {#benchmark}" + +msgid "" +"This section shows benchmark result against English Wikipedia. You can find be" +"nchmark script at https://github.com/groonga/wikipedia-search/blob/master/benc" +"hmark/centos7/postgresql.sh ." +msgstr "" +"このセクションでは英語版Wikipediaを使ったベンチマーク結果を示します。ベンチマークスクリプトは https://github.com/groonga" +"/wikipedia-search/blob/master/benchmark/centos7/postgresql.sh にあります。" + +msgid "### Summary" +msgstr "### 概要" + +msgid "Here is the summary of full text search index creation benchmark result:" +msgstr "以下は全文検索インデックス作成のベンチマーク結果の概要です。" + +msgid " * PGroonga is the fastest module." +msgstr " * PGroongaが一番速いモジュールです。" + +msgid " * pg\\_trgm is about 30% slower than PGroonga." +msgstr " * pg\\_trgmはPGroongaよりも30%遅いです。" + +msgid " * textsearch is about 2 times slower than PGroonga." +msgstr " * textsearchはPGroongaよりも2倍遅いです。" + +msgid "" +"" +msgstr "" + +msgid "Here is the summary of full text search index size benchmark result:" +msgstr "以下は全文検索インデックスのサイズのベンチマーク結果の概要です。" + +msgid " * pg\\_trgm is the smallest module." +msgstr " * pg\\_trgmが一番小さいモジュールです。" + +msgid " * textsearch is about 60% larger than pg\\_trgm." +msgstr " * textsearchはpg\\_trgmよりも60%大きいです。" + +msgid " * PGroonga is about 5 times larger than pg\\_trgm." +msgstr " * PGroongaはpg\\_trgmよりも5倍大きいです。" + +msgid "" +msgstr "" + +msgid "Here is the summary of full text search performance benchmark result:" +msgstr "以下は全文検索性能のベンチマーク結果の概要です。" + +msgid "" +" * Full text search performance by pg\\_trgm is very slower than other modules" +"." +msgstr " * pg\\_trgmの全文検索性能は他のモジュールよりも圧倒的に悪いです。" + +msgid " * Full text search performances of PGroonga and textsearch are similar." +msgstr " * PGroongaとtextsearchの全文検索性能は同じくらいです。" + +msgid "" +" * Full text search performance of Groonga, full text search engine by PGroon" +"ga, is faster than PGroonga and textsearch. It's 10 times or more faster." +msgstr "" +" * Groongaの全文検索機能はPGroonga・textsearchよりも10倍以上高速です。GroongaはPGroongaが使っている全文検索エ" +"ンジンです。" + +msgid "" +"" +msgstr "" + +msgid "" +"Here is the full text search performance graph without pg\\_trgm because pg\\_tr" +"gm is too slow:" +msgstr "以下はpg\\_trgmが遅すぎるのでpg\\_trgmを除いた全文検索性能のグラフです。" + +msgid "" +"" +msgstr "" +"" + +msgid "### Environment" +msgstr "### 環境" + +msgid "Here is the benchmark environment:" +msgstr "以下はベンチマーク環境です。" + +msgid "" +"CPU | Intel(R) Xeon(R) CPU E5-2660 v3****@2***** (24cores)\n" +"Memory | 32GiB\n" +"Swap | 2GiB\n" +"Storage | SSD (500GB)\n" +"OS | CentOS 7.2" +msgstr "" +"CPU | Intel(R) Xeon(R) CPU E5-2660 v3****@2***** (24cores)\n" +"メモリー | 32GiB\n" +"スワップ | 2GiB\n" +"ストレージ | SSD (500GB)\n" +"OS | CentOS 7.2" + +msgid "### Version" +msgstr "### バージョン" + +msgid "Here are the software versions:" +msgstr "以下はソフトウェアのバージョンです。" + +msgid "" +"PostgreSQL | PGroonga\n" +"---------- | --------\n" +"9.6.1 | 1.1.9" +msgstr "" + +msgid "### Data" +msgstr "### データ" + +msgid "Here are statistics of the target data:" +msgstr "以下は対象データの統計情報です。" + +msgid "" +"Size | About 33GiB\n" +"The number of records | About 5.3millions\n" +"The average of title length in byte | About 19.6B\n" +"The max title length in byte | 211B\n" +"The average of body length in byte | About 6.4KiB\n" +"The max body length in byte | About 1MiB (1047190B)" +msgstr "" +"サイズ | 約33GiB\n" +"レコード数 | 約530万件\n" +"タイトルの平均バイト数 | 約19.6B\n" +"タイトルの最大バイト数 | 211B\n" +"本文の平均バイト数 | 約6.4KiB\n" +"本文の最大バイト数 | 約1MiB(1047190B)" + +msgid "" +"It's important for textsearch that the max body length in byte is less than 1M" +"iB. If it's equals to `1MiB - 1B` or more, you can't create textsearch index w" +"ith the following error message:" +msgstr "" +"本文の最大バイト数が1MiB未満なのはtextsearchには重要なポイントです。もし、1MiB - 1B以上なら以下のエラーが発生してtextsearch" +"のインデックスを作成できないからです。" + +msgid "" +"```text\n" +"string is too long for tsvector (1618908 bytes, max 1048575 bytes)\n" +"```" +msgstr "" + +msgid "### Data load" +msgstr "### データロード" + +msgid "" +"Here is the benchmark result of data load. It's not related with full text sea" +"rch modules. Because any indexes aren't created yet." +msgstr "以下はデータロードのベンチマーク結果です。全文検索モジュールには依存しません。なぜならどのインデックスもまだ作られていないからです。" + +msgid "" +"Elapsed time | Database size\n" +"--------------- | -------------\n" +"About 26minutes | About 21GB" +msgstr "" +"経過時間 | データベースサイズ\n" +"-------- | -----------------\n" +"約26分 | 約21GB" + +msgid "Here is the SQL to load data:" +msgstr "以下はデータをロードするSQLです。" + +msgid "" +"```sql\n" +"COPY wikipedia FROM 'en-all-pages.csv' WITH CSV ENCODING 'utf8';\n" +"```" +msgstr "" + +msgid "" +"You can download the CSV data at http://packages.groonga.org/tmp/en-all-pages." +"csv.xz ." +msgstr "このCSVデータは http://packages.groonga.org/tmp/en-all-pages.csv.xz からダウンロードできます。" + +msgid "Here is the SQL to define the `wikipedia` table:" +msgstr "以下は`wikipedia`テーブルを定義するSQLです。" + +msgid "" +"```sql\n" +"CREATE TABLE wikipedia (\n" +" id integer PRIMARY KEY,\n" +" title text,\n" +" text text\n" +");\n" +"```" +msgstr "" + +msgid "### Index creation" +msgstr "### インデックス作成" + +msgid "Here are benchmark results of creating full text search indexes:" +msgstr "以下は全文検索インデックス作成のベンチマーク結果です。" + +msgid "" +"Module | Elapsed time | Index size | Note\n" +"---------- | ---------------------- | ----------- | --------------------------" +"------------------------------------------------------------------------------" +"-----\n" +"PGroonga | About 1hour 24minutes | About 39GB | PGroonga copies data and c" +"reates index from them. Data are compressed by zlib. Index only size is about " +"21GB.\n" +"textsearch | About 2hours 53minutes | About 12GB | `maintenance_work_mem` is " +"`2GB`. There are 3923 words that can't be indexed. (*)\n" +"pg\\_trgm | About 1hour 50minutes | About 7.6GB | `maintenance_work_mem` is " +"`2GB`." +msgstr "" +"モジュール | 経過時間 | インデックスのサイズ | 備考\n" +"---------- | ----------- | ------------------ | ------------------------------" +"------------------------------------------------------------------------------" +"--------------------\n" +"PGroonga | 約1時間24分 | 約39GB | PGroongaはデータをコピーしてそれに対してインデックスを作成しま" +"す。データはzlibで圧縮しています。インデックスだけのサイズは約27GBです。\n" +"textsearch | 約2時間53分 | 約12GB | `maintenance_work_mem`は`2GB`です。インデッ" +"クスに登録できなかった単語が3923あります。(*)\n" +"pg\\_trgm | 約1時間50分 | 約7.6GB | `maintenance_work_mem`は`2GB`です。" + +msgid "(*) Here is the error message of the case:" +msgstr "(*) このケースが発生したときのエラーメッセージは以下の通りです。" + +msgid "" +"```text\n" +"NOTICE: word is too long to be indexed\n" +"DETAIL: Words longer than 2047 characters are ignored.\n" +"```" +msgstr "" + +msgid "Here is the index definition of PGroonga:" +msgstr "PGroongaのインデックス定義は以下の通りです。" + +msgid "" +"```sql\n" +"CREATE INDEX wikipedia_index_pgroonga ON wikipedia\n" +" USING pgroonga (title, text);\n" +"```" +msgstr "" + +msgid "Here is the index definition of textsearch:" +msgstr "textsearchのインデックス定義は以下の通りです。" + +msgid "" +"```sql\n" +"CREATE INDEX wikipedia_index_textsearch ON wikipedia\n" +" USING GIN (to_tsvector('english', title),\n" +" to_tsvector('english', text));\n" +"```" +msgstr "" + +msgid "Here is the index definition of pg\\_trgm:" +msgstr "pg\\_trgmのインデックス定義は以下の通りです。" + +msgid "" +"```sql\n" +"CREATE INDEX wikipedia_index_pg_trgm ON wikipedia\n" +" USING GIN (title gin_trgm_ops, text gin_trgm_ops);\n" +"```" +msgstr "" + +msgid "### Full text search" +msgstr "### 全文検索" + +msgid "Here are benchmark results of full text searches." +msgstr "全文検索のベンチマーク結果は以下の通りです。" + +msgid "" +" * \"Groonga\" means `pgroonga.command('select ...')` result. See also [`pgroon" +"ga.command`](functions/pgroonga-command.html)." +msgstr "" +" * 「Groonga」は`pgroonga.command('select ...')`の結果です。[`pgroonga.command`](funct" +"ions/pgroonga-command.html)も参照してください。" + +msgid "" +" * \"Relative elapsed time\" is the ratio between the target elapsed time and t" +"he fastest case elapsed time. Larger means slower." +msgstr " * 「相対経過時間」は対象の経過時間と最速のケースの経過時間の比率です。大きいほど遅いです。" + +msgid "Query: \"animation\"" +msgstr "クエリー:「animation」" + +msgid "" +"Module | Elapsed time | N hits | Relative elapsed time | Note\n" +"---------- | ------------ | ------------------ | --------------------- | ----\n" +"PGroonga | About 173ms | About 40thousands | About 29 |\n" +"Groonga | About 6ms | About 40thousands | 1 |\n" +"textsearch | About 1s | About 420thousands | About 167 | N hit" +"s is about 10 times than other cases. It's caused by stemming. \"animation\" is " +"stemmed as \"anim\" and \"anim\" is searched.\n" +"pg\\_trgm | About 44s | About 30thousands | About 7333 |" +msgstr "" +"モジュール | 経過時間 | ヒット数 | 相対経過時間 | 備考\n" +"---------- | ------------ | -------- | ----------- | ----\n" +"PGroonga | 約173ミリ秒 | 約4万件 | 約29 |\n" +"Groonga | 約6ミリ秒 | 約4万件 | 1 |\n" +"textsearch | 約1秒 | 約42万件 | 約167 | 他のケースよりもヒット数が10倍多いです。これはステミングの" +"ためです。「animation」はステミングされると「anim」になり、「anim」で検索しています。\n" +"pg\\_trgm | 約44秒 | 約3万件 | 約7333 |" + +msgid "Query: \"database\"" +msgstr "クエリー:「database」" + +msgid "" +"Module | Elapsed time | N hits | Relative elapsed time\n" +"---------- | ------------ | ------------------ | ---------------------\n" +"PGroonga | About 698ms | About 210thousands | About 37\n" +"Groonga | About 19ms | About 210thousands | 1\n" +"textsearch | About 602ms | About 190thousands | About 32\n" +"pg\\_trgm | About 33s | About 130thousands | About 1736" +msgstr "" +"モジュール | 経過時間 | ヒット数 | 相対経過時間\n" +"---------- | ----------- | -------- | -----------\n" +"PGroonga | 約698ミリ秒 | 約21万件 | 約37\n" +"Groonga | 約19ミリ秒 | 約21万件 | 1\n" +"textsearch | 約602ミリ秒 | 約19万件 | 約32\n" +"pg\\_trgm | 約33秒 | 約13万件 | 約1736" + +msgid "Query: \"PostgreSQL OR MySQL\"" +msgstr "クエリー:「PostgreSQL OR MySQL」" + +msgid "" +"Module | Elapsed time | N hits | Relative elapsed time\n" +"---------- | ------------ | ------------------ | ---------------------\n" +"PGroonga | About 6ms | 1636 | About 2\n" +"Groonga | About 3ms | 1636 | 1\n" +"textsearch | About 3ms | 1506 | 1\n" +"pg\\_trgm | About 241ms | 1484 | About 80" +msgstr "" +"モジュール | 経過時間 | ヒット数 | 相対経過時間\n" +"---------- | ---------- | -------- | -----------\n" +"PGroonga | 約6ミリ秒 | 1636件 | 約2\n" +"Groonga | 約3ミリ秒 | 1636件 | 1\n" +"textsearch | 約3ミリ秒 | 1506件 | 1\n" +"pg\\_trgm | 約241ミリ秒 | 1484件 | 約80" + +msgid "Query: \"America\"" +msgstr "クエリー:「America」" + +msgid "" +"Module | Elapsed time | N hits | Relative elapsed time\n" +"---------- | ------------ | ------------------ | ---------------------\n" +"PGroonga | About 1.3s | About 470thousands | About 29\n" +"Groonga | About 45ms | About 470thousands | 1\n" +"textsearch | About 1.2s | About 480thousands | About 26\n" +"pg\\_trgm | About 1m32s | About 1.4millions | About 2044" +msgstr "" +"モジュール | 経過時間 | ヒット件数 | 相対経過時間\n" +"---------- | ---------- | ---------- | -----------\n" +"PGroonga | 約1.3秒 | 約47万件 | 約29\n" +"Groonga | 約45ミリ秒 | 約47万件 | 1\n" +"textsearch | 約1.2秒 | 約48万件 | 約26\n" +"pg\\_trgm | 約1分32秒 | 約140万件 | 約2044" Added: ja/reference/pgroonga-versus-textsearch-and-pg-trgm.md (+250 -0) 100644 =================================================================== --- /dev/null +++ ja/reference/pgroonga-versus-textsearch-and-pg-trgm.md 2016-11-18 17:48:56 +0900 (385518c) @@ -0,0 +1,250 @@ +--- +title: PGroonga対textsearch対pg_trgm +--- + +# PGroonga対textsearch対pg\_trgm + +PostgreSQLは2つの全文検索モジュールを提供しています。[textsearch]({{ site.postgresql_doc_base_url.ja }}/textsearch.html)と[pg\_trgm]({{ site.postgresql_doc_base_url.ja }}/pgtrgm.html)です。 + +textsearchモジュールはPostgreSQL組み込みの全文検索機能です。GiSTインデックスとGINインデックスをサポートしています。GiSTインデックスまたはGINインデックスを使うと全文検索性能を高めることができます。 + +pg\_trgmモジュールはcontribモジュールです。pg\_trgmは全文検索機能を提供します。pg\_trgmもGiSTインデックスとGINインデックスをサポートしています。GiSTインデックスまたはGINインデックスを使うと全文検索機能を高めることができます。 + +このドキュメントはPGroongaとtextsearchとpg\_trgmの違いを説明します。 + +## 特徴 + +各モジュールの特徴は次の通りです。 + +### PGroonga {#pgroonga} + +PGroongaは言語に特化した全文検索も言語に依存しない全文検索もどちらもサポートしています。PGroongaはデフォルトでは言語に依存しない全文検索を使います。通常、PGroongaはデフォルトで十分満足のいく全文検索結果を返します。 + +PGroongaはデフォルトで言語に依存しない全文検索を使うので、デフォルトですべての言語をサポートしています。ソースコードを変更する必要はありません。 + +「recheck」する必要がないのでPGroongaの検索は高速です。 + +PGroongaは更新中の検索をブロックしないので更新中も高速に検索できます。PGroongaは更新中も検索性能を落としません。 + +PGroongaは更新も高速です。 + +PGroongaはPostgreSQLに保存しているインデックス対象のテキストも保存しているのでインデックスサイズは大きいです。 + +### textsearchモジュール {#textsearch} + +textsearchモジュールは言語に特化した全文検索を実装しています。英語の単語はステミングされます。「work」も「works」も「worked」もすべて「work」に変換します。ステミングは[再現率](https://ja.wikipedia.org/wiki/%E6%83%85%E5%A0%B1%E6%A4%9C%E7%B4%A2#.E6.A4.9C.E7.B4.A2.E6.80.A7.E8.83.BD.E3.81.AE.E8.A9.95.E4.BE.A1)を高めます。 + +言語に特価した全文検索はよりよい全文検索機能になるかもしれません。しかし、「言語に特化」しているということはだれかが「言語に特化」した処理をじっそうしなければいけないということです。PostgreSQL 9.6.1は英語やフランス語やロシア語と言った15の言語をサポートしています。しかし、日本語や中国語、韓国語を含むアジアの言語など多くの言語は未対応です。 + +textsearchモジュールは「recheck」する必要がないので検索は高速です。(重み機能を使う場合は「recheck」が必要です。) + +textsearchモジュールは大きなテキストを扱うことができません。テキストの最大バイト数は`1MiB - 1B`です。1MiB以上のテキストを追加した場合は次のエラーが発生します。 + +```text +string is too long for tsvector (XXX bytes, max 1048575 bytes) +``` + +### pg\_trgmモジュール {#pg-trgm} + +pg\_trgmモジュールは言語に依存しない全文検索を実装しています。しかし、pg\_trgmはASCII以外の文字のサポートが無効になっています。つまり、デフォルトでは日本語や中国語といったアジアの言語はサポートしていないということです。ASCII以外の言語もサポートするには`contrib/pg_trgm/trgm.h`内の次の行をコメントアウトする必要があります。 + +```c +#define KEEPONLYALNUM +``` + +Debianベースのシステムを使っている場合は`C.UTF-8`ロケールを使うことでpg\_trgmのソースコードを変更しなくても非ASCII文字サポートを有効にできます。 + +pg\_trgmモジュールは大量のドキュメントがマッチして各ドキュメントが長い場合は遅いです。なぜならpg\_trgmはインデックスを使った検索のあとに「recheck」する必要があるからです。 + +### 概要 {#summary} + +モジュール | サポートしている言語 | 検索 | 更新 | インデックスサイズ +---------- | ------------------------------------ | ------- | ------------ | ------- +PGroonga | 全言語 | 速い | 速い | 大きい +textsearch | 15(アジアの言語は未サポート) | 速い | とても遅い | 小さい +pg\_trgm | ASCIIのみの言語 | 遅い | 遅い | 小さい + +## ベンチマーク {#benchmark} + +このセクションでは英語版Wikipediaを使ったベンチマーク結果を示します。ベンチマークスクリプトは https://github.com/groonga/wikipedia-search/blob/master/benchmark/centos7/postgresql.sh にあります。 + +### 概要 + +以下は全文検索インデックス作成のベンチマーク結果の概要です。 + + * PGroongaが一番速いモジュールです。 + + * pg\_trgmはPGroongaよりも30%遅いです。 + + * textsearchはPGroongaよりも2倍遅いです。 + + + +以下は全文検索インデックスのサイズのベンチマーク結果の概要です。 + + * pg\_trgmが一番小さいモジュールです。 + + * textsearchはpg\_trgmよりも60%大きいです。 + + * PGroongaはpg\_trgmよりも5倍大きいです。 + + + +以下は全文検索性能のベンチマーク結果の概要です。 + + * pg\_trgmの全文検索性能は他のモジュールよりも圧倒的に悪いです。 + + * PGroongaとtextsearchの全文検索性能は同じくらいです。 + + * Groongaの全文検索機能はPGroonga・textsearchよりも10倍以上高速です。GroongaはPGroongaが使っている全文検索エンジンです。 + + + +以下はpg\_trgmが遅すぎるのでpg\_trgmを除いた全文検索性能のグラフです。 + + + +### 環境 + +以下はベンチマーク環境です。 + +CPU | Intel(R) Xeon(R) CPU E5-2660 v3****@2***** (24cores) +メモリー | 32GiB +スワップ | 2GiB +ストレージ | SSD (500GB) +OS | CentOS 7.2 + +### バージョン + +以下はソフトウェアのバージョンです。 + +PostgreSQL | PGroonga +---------- | -------- +9.6.1 | 1.1.9 + +### データ + +以下は対象データの統計情報です。 + +サイズ | 約33GiB +レコード数 | 約530万件 +タイトルの平均バイト数 | 約19.6B +タイトルの最大バイト数 | 211B +本文の平均バイト数 | 約6.4KiB +本文の最大バイト数 | 約1MiB(1047190B) + +本文の最大バイト数が1MiB未満なのはtextsearchには重要なポイントです。もし、1MiB - 1B以上なら以下のエラーが発生してtextsearchのインデックスを作成できないからです。 + +```text +string is too long for tsvector (1618908 bytes, max 1048575 bytes) +``` + +### データロード + +以下はデータロードのベンチマーク結果です。全文検索モジュールには依存しません。なぜならどのインデックスもまだ作られていないからです。 + +経過時間 | データベースサイズ +-------- | ----------------- +約26分 | 約21GB + +以下はデータをロードするSQLです。 + +```sql +COPY wikipedia FROM 'en-all-pages.csv' WITH CSV ENCODING 'utf8'; +``` + +このCSVデータは http://packages.groonga.org/tmp/en-all-pages.csv.xz からダウンロードできます。 + +以下は`wikipedia`テーブルを定義するSQLです。 + +```sql +CREATE TABLE wikipedia ( + id integer PRIMARY KEY, + title text, + text text +); +``` + +### インデックス作成 + +以下は全文検索インデックス作成のベンチマーク結果です。 + +モジュール | 経過時間 | インデックスのサイズ | 備考 +---------- | ----------- | ------------------ | -------------------------------------------------------------------------------------------------------------------------------- +PGroonga | 約1時間24分 | 約39GB | PGroongaはデータをコピーしてそれに対してインデックスを作成します。データはzlibで圧縮しています。インデックスだけのサイズは約27GBです。 +textsearch | 約2時間53分 | 約12GB | `maintenance_work_mem`は`2GB`です。インデックスに登録できなかった単語が3923あります。(*) +pg\_trgm | 約1時間50分 | 約7.6GB | `maintenance_work_mem`は`2GB`です。 + +(*) このケースが発生したときのエラーメッセージは以下の通りです。 + +```text +NOTICE: word is too long to be indexed +DETAIL: Words longer than 2047 characters are ignored. +``` + +PGroongaのインデックス定義は以下の通りです。 + +```sql +CREATE INDEX wikipedia_index_pgroonga ON wikipedia + USING pgroonga (title, text); +``` + +textsearchのインデックス定義は以下の通りです。 + +```sql +CREATE INDEX wikipedia_index_textsearch ON wikipedia + USING GIN (to_tsvector('english', title), + to_tsvector('english', text)); +``` + +pg\_trgmのインデックス定義は以下の通りです。 + +```sql +CREATE INDEX wikipedia_index_pg_trgm ON wikipedia + USING GIN (title gin_trgm_ops, text gin_trgm_ops); +``` + +### 全文検索 + +全文検索のベンチマーク結果は以下の通りです。 + + * 「Groonga」は`pgroonga.command('select ...')`の結果です。[`pgroonga.command`](functions/pgroonga-command.html)も参照してください。 + + * 「相対経過時間」は対象の経過時間と最速のケースの経過時間の比率です。大きいほど遅いです。 + +クエリー:「animation」 + +モジュール | 経過時間 | ヒット数 | 相対経過時間 | 備考 +---------- | ------------ | -------- | ----------- | ---- +PGroonga | 約173ミリ秒 | 約4万件 | 約29 | +Groonga | 約6ミリ秒 | 約4万件 | 1 | +textsearch | 約1秒 | 約42万件 | 約167 | 他のケースよりもヒット数が10倍多いです。これはステミングのためです。「animation」はステミングされると「anim」になり、「anim」で検索しています。 +pg\_trgm | 約44秒 | 約3万件 | 約7333 | + +クエリー:「database」 + +モジュール | 経過時間 | ヒット数 | 相対経過時間 +---------- | ----------- | -------- | ----------- +PGroonga | 約698ミリ秒 | 約21万件 | 約37 +Groonga | 約19ミリ秒 | 約21万件 | 1 +textsearch | 約602ミリ秒 | 約19万件 | 約32 +pg\_trgm | 約33秒 | 約13万件 | 約1736 + + +クエリー:「PostgreSQL OR MySQL」 + +モジュール | 経過時間 | ヒット数 | 相対経過時間 +---------- | ---------- | -------- | ----------- +PGroonga | 約6ミリ秒 | 1636件 | 約2 +Groonga | 約3ミリ秒 | 1636件 | 1 +textsearch | 約3ミリ秒 | 1506件 | 1 +pg\_trgm | 約241ミリ秒 | 1484件 | 約80 + +クエリー:「America」 + +モジュール | 経過時間 | ヒット件数 | 相対経過時間 +---------- | ---------- | ---------- | ----------- +PGroonga | 約1.3秒 | 約47万件 | 約29 +Groonga | 約45ミリ秒 | 約47万件 | 1 +textsearch | 約1.2秒 | 約48万件 | 約26 +pg\_trgm | 約1分32秒 | 約140万件 | 約2044 Modified: reference/pgroonga-versus-textsearch-and-pg-trgm.md (+15 -17) =================================================================== --- reference/pgroonga-versus-textsearch-and-pg-trgm.md 2016-11-17 14:11:05 +0900 (206f3f7) +++ reference/pgroonga-versus-textsearch-and-pg-trgm.md 2016-11-18 17:48:56 +0900 (a66d6c0) @@ -84,7 +84,7 @@ Here is the summary of full text search index size benchmark result: * pg\_trgm is the smallest module. - * textsearch is about 60% lager than pg\_trgm. + * textsearch is about 60% larger than pg\_trgm. * PGroonga is about 5 times larger than pg\_trgm. @@ -133,7 +133,7 @@ The max title length in byte | 211B The average of body length in byte | About 6.4KiB The max body length in byte | About 1MiB (1047190B) -It's important for textsearch that the max body length in byte is less than 1MiB. If it's equals to 1MiB - 1 or more, you can't create textsearch index with the following error message: +It's important for textsearch that the max body length in byte is less than 1MiB. If it's equals to `1MiB - 1B` or more, you can't create textsearch index with the following error message: ```text string is too long for tsvector (1618908 bytes, max 1048575 bytes) @@ -208,25 +208,23 @@ CREATE INDEX wikipedia_index_pg_trgm ON wikipedia Here are benchmark results of full text searches. - * "Groonga" means `pgroonga.command('select ...')` result. See also [`pgroonga.command`](functions/pgroonga-command.html) + * "Groonga" means `pgroonga.command('select ...')` result. See also [`pgroonga.command`](functions/pgroonga-command.html). * "Relative elapsed time" is the ratio between the target elapsed time and the fastest case elapsed time. Larger means slower. -TODO: Graph as summary - Query: "animation" -Module | Elapsed time | N hits | Relative time | Note ----------- | ------------ | ------------------ | ------------- | ---- -PGroonga | About 173ms | About 40thousands | About 29 | -Groonga | About 6ms | About 40thousands | 1 | -textsearch | About 1s | About 420thousands | About 167 | N hits is about 10 times than other cases. It's caused by stemming. "animation" is stemmed as "anim" and "anim" is searched. -pg\_trgm | About 44s | About 30thousands | About 7333 | +Module | Elapsed time | N hits | Relative elapsed time | Note +---------- | ------------ | ------------------ | --------------------- | ---- +PGroonga | About 173ms | About 40thousands | About 29 | +Groonga | About 6ms | About 40thousands | 1 | +textsearch | About 1s | About 420thousands | About 167 | N hits is about 10 times than other cases. It's caused by stemming. "animation" is stemmed as "anim" and "anim" is searched. +pg\_trgm | About 44s | About 30thousands | About 7333 | Query: "database" -Module | Elapsed time | N hits | Relative time ----------- | ------------ | ------------------ | ------------- +Module | Elapsed time | N hits | Relative elapsed time +---------- | ------------ | ------------------ | --------------------- PGroonga | About 698ms | About 210thousands | About 37 Groonga | About 19ms | About 210thousands | 1 textsearch | About 602ms | About 190thousands | About 32 @@ -235,8 +233,8 @@ pg\_trgm | About 33s | About 130thousands | About 1736 Query: "PostgreSQL OR MySQL" -Module | Elapsed time | N hits | Relative time ----------- | ------------ | ------------------ | ------------- +Module | Elapsed time | N hits | Relative elapsed time +---------- | ------------ | ------------------ | --------------------- PGroonga | About 6ms | 1636 | About 2 Groonga | About 3ms | 1636 | 1 textsearch | About 3ms | 1506 | 1 @@ -244,8 +242,8 @@ pg\_trgm | About 241ms | 1484 | About 80 Query: "America" -Module | Elapsed time | N hits | Relative time ----------- | ------------ | ------------------ | ------------- +Module | Elapsed time | N hits | Relative elapsed time +---------- | ------------ | ------------------ | --------------------- PGroonga | About 1.3s | About 470thousands | About 29 Groonga | About 45ms | About 470thousands | 1 textsearch | About 1.2s | About 480thousands | About 26 -------------- next part -------------- HTML����������������������������...Download