![[PostgreSQL] GIN์ธ๋ฑ์ค์ ์๋ฆฌ ๋ฐ ํน์ง](/images/posts/10/img.png)
[PostgreSQL] GIN์ธ๋ฑ์ค์ ์๋ฆฌ ๋ฐ ํน์ง
1. GIN ์ธ๋ฑ์ค๋? Generalized Inverted Index์ ์ฝ์์ด๋ค. ์ด์ ํฌ์คํธ์ธ full text search์์ ์ฌ์ฉํ๋ ์ธ๋ฑ์ค์ ์ ํ. ๊ธฐ๋ณธ ๊ตฌ์กฐ๋ B-tree์ ์ ์ฌํ์ง๋ง, ์ ์ฅ ํํ๊ฐ ๋ค๋ฅด๋ค.ย ์ ์ฅ๋ ์์ ์์ ์ ๋ํ ๊ฒ์์ด ์๋ ์ธ๋ฑ์ค ์ปฌ๋ผ์ ๊ฐ์ split ํ token์ธ lexeme ๋ฐฐ์ด์ ๋ํด์ ๊ฒ์์ ํ๋ค. array_ops, tsvector_ops, jsonb_ops, jsonb_path_ops ๋ฑ ์ built-in operators๋ฅผ ํตํด ์ ๊ทผ์ด ๊ฐ๋ฅํ๋ค. 2. full text search์์์ ์ ์ฉ 2-1. ์ํ ํ ์ด๋ธ ๋ฐ ๋ฐ์ดํฐ ์์ฑ create table ts(doc text, doc_tsv tsvector); insert into ts(doc) values ('Can a sheet slitter slit sheets?'), ('How many sheets could a sheet slitter slit?'), ('I slit a sheet, a sheet I slit.'), ('Upon a slitted sheet I sit.'), ('Whoever slit the sheets is a good sheet slitter.'), ('I am a sheet slitter.'), ('I slit sheets.'), ('I am the sleekest sheet slitter that ever slit sheets.'), ('She slits the sheet she sits on.'); update ts set doc_tsv = to_tsvector(doc); create index on ts using gin(doc_tsv); select doc from ts where doc_tsv @@ to_tsquery('many & slitter'); 2-2. ์กฐํ ๊ฒฐ๊ณผ ๋ฐ ํ๋ ํ์ธ QUERY PLAN --------------------------------------------------------------------- Bitmap Heap Scan on ts Recheck Cond: (doc_tsv @@ to_tsquery('many & slitter'::text)) -> Bitmap Index Scan on ts_doc_tsv_idx Index Cond: (doc_tsv @@ to_tsquery('many & slitter'::text)) (4 rows) ...
![[PostgreSQL] SP-GiST์ธ๋ฑ์ค์ ์๋ฆฌ ๋ฐ ํน์ง](/images/posts/9/img.png)
![[PostgreSQL] GiST์ธ๋ฑ์ค์ ์๋ฆฌ ๋ฐ ํน์ง](/images/posts/8/img.png)
![[PostgreSQL] Hash ์ธ๋ฑ์ค์ ์๋ฆฌ ๋ฐ ํน์ง](/images/posts/7/img.png)
![[PostgreSQL] B-tree ์ธ๋ฑ์ค์ ์๋ฆฌ ๋ฐ ํน์ง](/images/posts/6/img.png)