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?

More than 3 years have passed since last update.

SQLアンチパターンを読んで

Posted at

読んだ本

image.png


2章 Naive Trees(素朴な木)

image.png

image.png

→深さに制限がない場合、ノードの数(スレッドのコメント数など)を数える場合など対応できない場合がある。


代替ツリーモデルを使用する

経路列挙

親からのパスを格納する。
image.png


閉包テーブル

ツリー全体のパスを別のテーブルに格納する
image.png


16章 Poor Man's Search Engine(貧者のサーチエンジン)

LIKE句を利用した中間一致検索
SELECT * FROM Bugs WHERE description LIKE '%crash%';

以下で中間・後方一致検索の性能を高められる。
基本的な解決策:ベンダー固有の全文検索エンジン

CREATE TABLE Bugs (
  bug_id SERIAL PRIMARY KEY,
  summary VARCHAR(80),
  description TEXT,
  ts_bugtext TSVECTOR
  -- 他の列. . .
);
CREATE TRIGGER ts_bugtext BEFORE INSERT OR UPDATE ON Bugs
FOR EACH ROW EXECUTE PROCEDURE
  tsvector_update_trigger(ts_bugtext, 'pg_catalog.english', summary, description);
GINインデックス
CREATE INDEX bugs_ts ON Bugs USING GIN(ts_bugtext);
SELECT * FROM Bugs WHERE ts_bugtext @@ to_tsquery('crash');
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?