PostgreSQL Conference Japan 2017の資料です。
PostgreSQLが苦手な全文検索機能を強力に補完する拡張機能PGroongaの最新情報を紹介します。PGroongaは単なる全文検索モジュールではありません。PostgreSQLで簡単にリッチな全文検索システムを実現するための機能一式を提供します。PGroongaは最新PostgreSQLへの対応も積極的です。例としてロジカルレプリケーションと組み合わせた活用方法も紹介します。
29回勉強会資料「PostgreSQLのリカバリ超入門」
See also http://www.interdb.jp/pgsql (Coming soon!)
初心者向け。PostgreSQLのWAL、CHECKPOINT、 オンラインバックアップの仕組み解説。
これを見たら、次は→ http://www.slideshare.net/satock/29shikumi-backup
Remixing Vol.3 with オールアバウト and LIG
https://remixing.doorkeeper.jp/events/34982
で発表した資料になります。
CMS開発を汎用CMSを使うのかフルスクラッチするのか。
また、LaravelでフルスクラッチCMSを作る時のノウハウなどについて。
【MT東京−31】バレンタインデー1ヶ月前から始めるSwift×MT Data APIでのLT登壇資料になります。
Firebaseを使用したサンプル作成にあたり、ファイルアップロード処理の際に実装に詰まった経験やデータ設計の整理に苦労しました。
その経験からFirebaseを扱いやすくするライブラリ「Salada」を導入してサンプルアプリを作成した際の知見や実装ポイント等をまとめました。
Redmineに全文検索エンジンGroongaサポートを追加する「Full Text Search」プラグインを紹介します。このプラグインを使えば数十万チケットがあるRedmineでも高速に目的の情報を見つけられます。高速になるという現状の話だけでなく、Redmine内のデータを有効活用するという今後の話もします。
RubyKaigi 2022 - Fast data processing with Ruby and Apache ArrowKouhei Sutou
I introduced Ruby and Apache Arrow integration including the "super fast large data interchange and processing" Apache Arrow feature at RubyKaigi Takeout 2021.
This talk introduces how we can use the "super fast large data interchange and processing" Apache Arrow feature in Ruby. Here are some use cases:
* Fast data retrieval (fast pluck) from DB such as MySQL and PostgreSQL for batch processes in a Ruby on Rails application
* Fast data interchange with JavaScript for dynamic visualization in a Ruby on Rails application
* Fast OLAP with in-process DB such as DuckDB and Apache Arrow DataFusion in a Ruby on Rails application or irb session
RubyKaigi Takeout 2021 - Red Arrow - Ruby and Apache ArrowKouhei Sutou
To use Ruby for data processing widely, Apache Arrow support is important. We can do the followings with Apache Arrow:
* Super fast large data interchange and processing
* Reading/writing data in several famous formats such as CSV and Apache Parquet
* Reading/writing partitioned large data on cloud storage such as Amazon S3
This talk describes the followings:
* What is Apache Arrow
* How to use Apache Arrow with Ruby
* How to integrate with Ruby 3.0 features such as MemoryView and Ractor
Apache Arrow 1.0 - A cross-language development platform for in-memory dataKouhei Sutou
Apache Arrow is a cross-language development platform for in-memory data. You can use Apache Arrow to process large data effectively in Python and other languages such as R. Apache Arrow is the future of data processing. Apache Arrow 1.0, the first major version, was released at 2020-07-24. It's a good time to know Apache Arrow and start using it.
Apache Arrow - A cross-language development platform for in-memory dataKouhei Sutou
Apache Arrow is the future for data processing systems. This talk describes how to solve data sharing overhead in data processing system such as Spark and PySpark. This talk also describes how to accelerate computation against your large data by Apache Arrow.
csv, one of the standard libraries, in Ruby 2.6 has many improvements:
* Default gemified
* Faster CSV parsing
* Faster CSV writing
* Clean new CSV parser implementation for further improvements
* Reconstructed test suites for further improvements
* Benchmark suites for further performance improvements
These improvements are done without breaking backward compatibility.
This talk describes details of these improvements by a new csv maintainer.
PGroonga 2 – Make PostgreSQL rich full text search system backend!Kouhei Sutou
PGroonga 2.0 has been released with 2 years development since PGroonga 1.0.0. PGroonga 1.0.0 just provides fast full text search with all languages support. It's important because it's a lacked feature in PostgreSQL. PGroonga 2.0 provides more useful features to implement rich full text search system with PostgreSQL. This session shows how to implement rich full text search system with PostgreSQL!
This talk describes about PGroonga that resolves these problems.
Improve extension API: C++ as better language for extensionKouhei Sutou
The document discusses improving the performance of Ruby extensions written in C++. It proposes using C++ as the language for extensions rather than C, as C++ has convenient features like type inference, lambda expressions, and default arguments that make extensions easier to write. It recommends providing a convenient API like Ext++ that allows defining Ruby classes and methods directly in C++ code similar to how it is done in Ruby. This avoids the verbosity of raw C APIs and allows leveraging modern C++ features for high performance extension code that stays within C++ as much as possible without moving between C++ and Ruby.
PGroonga is fast and flexible full text search extension for PostgreSQL. Zulip is a chat tool that uses PostgreSQL and PGroonga. This talk describes why PGroonga is suitable for Zulip.
28. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
ベンチマーク:pg_bigm
0
0.5
1
1.5
2
2.5
3
311 14706 20389
Data: Japanese Wikipedia
(Many records and large documents)
N records: About 0.9millions
Average text size: 6.7KiB
Slow
Slow
Elapsedtime(sec)
(Lowerisbetter)
N hits
pg_bigm
29. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
ベンチマーク:PGroonga
0
0.5
1
1.5
2
2.5
3
311 14706 20389
Data: Japanese Wikipedia
(Many records and large documents)
N records: About 0.9millions
Average text size: 6.7KiB
Fast Fast
Elapsedtime(sec)
(Lowerisbetter)
N hits
PGroonga pg_bigm
32. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
高度な機能
オートコンプリート
ローマ字対応(zen→全文検索)
類似文書検索
同義語展開
「牛乳」→
「牛乳 OR ミルク」
33. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
高速全文検索+ソート
34. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
テーブル定義
CREATE TABLE entries (
-- 主キーを用意する
-- それっぽい順でソートするために必要
id integer PRIMARY KEY,
title text,
content text
);
35. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
インデックス定義
-- 全文検索用インデックス
-- よくわからないなら
-- デフォルトのまま使うこと!
CREATE INDEX entries_full_text_search
ON entries
--「USING PGroonga」=「PGroongaを使う」
-- 主キーはそれっぽい順ソートのため!
USING PGroonga (id, title, content);
36. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
データ挿入
-- 普通に挿入するだけでよい
INSERT INTO entries
VALUES (1,
'Groongaで高速全文検索!',
'高速に全文検索したいですね!');
37. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
全文検索
SELECT title FROM entries
WHERE
-- &@~で全文検索
-- 「検索」と「高速」をAND検索
title &@~ '検索 高速' OR
content &@~ '検索 高速';
38. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
全文検索:LIKE
SELECT title FROM entries
WHERE
-- LIKEでもインデックスが効く
--=アプリを書き換えずに高速化可能
-- ただし&@~より性能が落ちる
title LIKE '%検索%' OR
content LIKE '%検索%';
39. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
それっぽい順のソート
SELECT
title,
-- pgroonga_score(テーブル名)で
-- それっぽさを数値で取得
pgroonga_score(entries) AS score
FROM entries
WHERE -- ...
-- それっぽさでソート
ORDER BY score DESC LIMIT 10;
40. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
キーワードハイライト
41. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
HTML用にハイライト
SELECT
pgroonga_highlight_html(
title,
-- クエリーから対象キーワードを抽出
pgroonga_query_extract_keywords('検索 高速'))
FROM entries
WHERE title &@~ '検索 高速' OR
content &@~ '検索 高速';
52. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
オートコンプリート
前方一致用インデックス
CREATE INDEX prefix_search ON terms
USING PGroonga
-- ...text_array_term_search...
(readings pgroonga_text_array_term_search_ops_v2);
53. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
オートコンプリート
緩い全文検索用
CREATE INDEX loose_search ON terms
USING PGroonga (term)
-- 緩い全文検索用トークナイザー
WITH (tokenizer='TokenBigramSplitSymbolAlphaDigit');
54. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
オートコンプリート
検索方法
SELECT term FROM terms
-- ヨミで前方一致検索
WHERE readings &^~ '${入力}' OR
-- 緩い全文検索
term &@ '${入力}'
ORDER BY term LIMIT 10; -- ソート
55. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
オートコンプリート
検索例:漢字1
-- ユーザーが「牛」を入力した場合
SELECT term FROM terms
-- ヨミで前方一致検索
WHERE readings &^~ '牛' OR
-- 緩い全文検索(ヒット)
term &@ '牛'
ORDER BY term LIMIT 10; -- ソート
56. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
オートコンプリート
検索例:漢字2
-- ユーザーが「乳」を入力した場合
SELECT term FROM terms
-- ヨミで前方一致検索
WHERE readings &^~ '乳' OR
-- 緩い全文検索(ヒット)
term &@ '乳'
ORDER BY term LIMIT 10; -- ソート
57. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
オートコンプリート
検索例:カタカナ
-- ユーザーが「ギュウ」を入力した場合
SELECT term FROM terms
-- ヨミで前方一致検索(ヒット)
WHERE readings &^~ 'ギュウ' OR
-- 緩い全文検索
term &@ 'ギュウ'
ORDER BY term LIMIT 10; -- ソート
58. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
オートコンプリート
検索例:ひらがな
-- ユーザーが「ぎゅう」を入力した場合
SELECT term FROM terms
-- ヨミで前方一致検索(ヒット)
WHERE readings &^~ 'ぎゅう' OR
-- 緩い全文検索
term &@ 'ぎゅう'
ORDER BY term LIMIT 10; -- ソート
59. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
オートコンプリート
検索例:ローマ字
-- ユーザーが「gyu」を入力した場合
SELECT term FROM terms
-- ヨミで前方一致検索(ヒット)
WHERE readings &^~ 'gyu' OR
-- 緩い全文検索
term &@ 'gyu'
ORDER BY term LIMIT 10; -- ソート
67. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
同義語展開:検索方法
SELECT title FROM entries
WHERE
-- title &@~ 'アイス ((牛乳) OR (ミルク))'になる
title &@~
pgroonga_query_expand('synonyms',
'term',
'terms',
'アイス 牛乳');
68. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
類似文書検索
92. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
ロジカルレプリケーション
テーブル作成
-- マスター
CREATE TABLE memos (
id integer PRIMARY KEY,
content text
);
CREATE INDEX
full_text_search_index ON memos
USING pgroonga (id, content);
93. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
ロジカルレプリケーション
レプリケーション用ユーザー作成
-- マスター
-- pg_hba.confも編集すること
CREATE ROLE replica
WITH REPLICATION
LOGIN PASSWORD 'pass';
GRANT SELECT
ON ALL TABLES IN SCHEMA public
TO replica;
94. PGroonga 2 - PostgreSQLでの全文検索の決定版 Powered by Rabbit 2.2.2
ロジカルレプリケーション
publication作成
-- マスター
CREATE PUBLICATION pub
FOR TABLE memos;