SlideShare a Scribd company logo
GIN vs. GiST 인덱스 이야기
가이아쓰리디㈜
박진우(swat018@gmail.com)
2017. 11. 04
Contents
1.Index
2.Heap
3.Btree and GIN
4.Ttree and GiST
5.summary
Why Index??
Why Index??
Spatial
Index
Visibility
Index
Full Text
Search
Index
Index
Index
인덱스는 지정된 컬럼에 대한 매핑 정보를 가지고 있습니다.
Ex) CREATE INDEX test1_id_index ON test1 (id);
Index
PostgreSQL에서는 다음과 같은 Index type을 지원합니다.
• B-Tree : numbers, text, dates, etc..
• Generalized Inverted Index (GIN)
• Generalized Inverted Search Tree (GiST)
• Space partitioned GiST (SP-GiST)
• Block Range Indexes (BRIN)
• Hash
Heap
Heap(힙) 이란?
: 정렬의 기준이 없이 저장된 테이블의 존재 형태
Block 0
Block 1
Block 2
Block 3
Block 4
Block 0
Block 1
Block 2
Block 3
Block 4
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
Heap
Block 0
Block 1
Block 2
Block 3
Block 4
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
0
1
2
3
TID: Physical location of heap tuple
ex) Berlin: 0번째 Block의 2번째 항목이다.
Item Point: Berlin  (0,2)
Heap
• Table file은 n개의 block으로 구성되어 있다.
• 한 block 당 Page의 디폴트 크기는 8192byte(약 8KB)이다.
• 한 페이지(Page)는 Header Info, Record data, free space로 구성되어 있다.
Heap
Seq. Scan VS. Index Scan
B-tree
Postgres=# CREATE INDEX indexname ON tablename (columnname)
CREATE INDEX test1_id_index ON test1 (id);
• 기본적인 Index type의 방식
• 사용법
B-tree
B-tree
GIN
Seoul
(0,12)
Seoul
(4,2)
Seoul
(1,9)
Seoul
(4,1)
Busan
(2,2)
Seoul
(0,12), (4,2),
(1,9), (4,1),
(2,2)
Busan
(2,2)
Posing list
• Generalized Inverted Index (GIN)
GIN
Posting tree
GIN
Posting list
GIN
1. Text retrival
postgres=# -- create a table with a text column
postgres=# CREATE TABLE t1 (id serial, t text);
CREATE TABLE
postgres=# CREATE INDEX t1_idx ON t1 USING gin (to_tsvector('english', t));
CREATE INDEX
postgres=# INSERT INTO t1 VALUES (1, 'a fat cat sat on a mat and ate a fat rat');
INSERT 0 1
postgres=# INSERT INTO t1 VALUES (2, 'a fat dog sat on a mat and ate a fat chop');
INSERT 0 1
postgres=# -- is there a row where column t contains the two words? (syntax contains some magic
to hit index)
postgres=# SELECT * FROM t1 WHERE to_tsvector('english', t) @@ to_tsquery('fat & rat');
id | t
----+------------------------------------------
1 | a fat cat sat on a mat and ate a fat rat
(1 row)
postgres=# CREATE INDEX indexname ON tablename USING GIN (columnname);
GIN
2. Array
postgres=# -- create a table where one column exists of an integer array
postgres=# --
postgres=# CREATE TABLE t2 (id serial, temperatures INTEGER[]);
CREATE TABLE
postgres=# CREATE INDEX t2_idx ON t2 USING gin (temperatures);
CREATE INDEX
postgres=# INSERT INTO t2 VALUES (1, '{11, 12, 13, 14}');
INSERT 0 1
postgres=# INSERT INTO t2 VALUES (2, '{21, 22, 23, 24}');
INSERT 0 1
postgres=# -- Is there a row with the two array elements 12 and 11?
postgres=# SELECT * FROM t2 WHERE temperatures @> '{12, 11}';
id | temperatures
----+---------------
1 | {11,12,13,14}
(1 row)
GiST
• “contains”, “left of”, “overlaps”, 등을 지원한다.
• Full Text Search, Geometric operations (PostGIS, etc. ), Handling ranges (tiem, etc.)
• KNN-search, BRTree를 바탕으로 구성되어 있다.
R-tree(Rectangle-tree)
R-tree(Rectangle-tree)
Linear Indexing
R-tree(Rectangle-tree)
Multi-Dimensional
R-tree(Rectangle-tree)
Multi-Dimensional
GiST
postgres=# CREATE INDEX indexname ON tablename USING GIST
(columnname);
postgres=# -- create a table with a column of non-trivial type
postgres=# --
postgres=# CREATE TABLE t3 (id serial, c circle);
CREATE TABLE
postgres=# CREATE INDEX t3_idx ON t3 USING gist(c);
CREATE INDEX
postgres=# INSERT INTO t3 VALUES (1, circle '((0, 0), 0.5)');
INSERT 0 1
postgres=# INSERT INTO t3 VALUES (2, circle '((1, 0), 0.5)');
INSERT 0 1
postgres=# INSERT INTO t3 VALUES (3, circle '((0.3, 0.3), 0.3)');
INSERT 0 1
postgres=# -- which circles lie in the bounds of the unit circle?
postgres=# SELECT * FROM t3 WHERE circle '((0, 0), 1)' @> c;
id | c
----+-----------------
1 | <(0,0),0.5>
3 | <(0.3,0.3),0.3>
(2 rows)
지원하는 Data type
지원하는 Data type
지원하는 Data type
summary
• B-tree is ideal for unique values
• GIN is ideal for indexes with many duplicates
• GIST for everything else
Experiments lead to the following observations:
creation time - GIN takes 3x time to build than GiST
size of index - GIN is 2-3 times bigger than GiST
search time - GIN is 3 times faster than GiST
update time - GIN is about 10 times slower than GiST
경청해 주셔서 감사합니다.
swat018@gmail.com

More Related Content

PDF
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
PDF
[Pgday.Seoul 2020] SQL Tuning
PDF
[Pgday.Seoul 2017] 7. PostgreSQL DB Tuning 기업사례 - 송춘자
PDF
PostgreSQL13でのレプリケーション関連の改善について(第14回PostgreSQLアンカンファレンス@オンライン)
PDF
PostgreSQL Performance Tuning
PDF
Pgday bdr 천정대
ODP
Introduction to PostgreSQL
PDF
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2017] 7. PostgreSQL DB Tuning 기업사례 - 송춘자
PostgreSQL13でのレプリケーション関連の改善について(第14回PostgreSQLアンカンファレンス@オンライン)
PostgreSQL Performance Tuning
Pgday bdr 천정대
Introduction to PostgreSQL
PostgreSQLのリカバリ超入門(もしくはWAL、CHECKPOINT、オンラインバックアップの仕組み)

What's hot (20)

PDF
これからLDAPを始めるなら 「389-ds」を使ってみよう
PDF
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
PDF
使いこなそうGUC
PDF
PostgreSQL のイケてるテクニック7選
PPTX
フックを使ったPostgreSQLの拡張機能を作ってみよう!(第33回PostgreSQLアンカンファレンス@オンライン 発表資料)
PDF
PostgreSQL: Advanced indexing
PDF
OSC北海道2014_JPUG資料
PDF
pg_bigmを用いた全文検索のしくみ(前編)
PDF
まずやっとくPostgreSQLチューニング
PDF
明日から使えるPostgre sql運用管理テクニック(監視編)
PDF
InnoDB Locking Explained with Stick Figures
PDF
pg_bigm(ピージーバイグラム)を用いた全文検索のしくみ
PDF
Inside vacuum - 第一回PostgreSQLプレ勉強会
PDF
外部データラッパによる PostgreSQL の拡張
PDF
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
PDF
pg_standbyの今後について(第19回PostgreSQLアンカンファレンス@オンライン 発表資料)
PDF
最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)
ODP
The PostgreSQL Query Planner
PDF
5ステップで始めるPostgreSQLレプリケーション@hbstudy#13
PPTX
PostgreSQL開発コミュニティに参加しよう!(PostgreSQL Conference Japan 2021 発表資料)
これからLDAPを始めるなら 「389-ds」を使ってみよう
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
使いこなそうGUC
PostgreSQL のイケてるテクニック7選
フックを使ったPostgreSQLの拡張機能を作ってみよう!(第33回PostgreSQLアンカンファレンス@オンライン 発表資料)
PostgreSQL: Advanced indexing
OSC北海道2014_JPUG資料
pg_bigmを用いた全文検索のしくみ(前編)
まずやっとくPostgreSQLチューニング
明日から使えるPostgre sql運用管理テクニック(監視編)
InnoDB Locking Explained with Stick Figures
pg_bigm(ピージーバイグラム)を用いた全文検索のしくみ
Inside vacuum - 第一回PostgreSQLプレ勉強会
外部データラッパによる PostgreSQL の拡張
Memoizeの仕組み(第41回PostgreSQLアンカンファレンス@オンライン 発表資料)
pg_standbyの今後について(第19回PostgreSQLアンカンファレンス@オンライン 発表資料)
最新機能までを総ざらい!PostgreSQLの注目機能を振り返る(第32回 中国地方DB勉強会 in 岡山 発表資料)
The PostgreSQL Query Planner
5ステップで始めるPostgreSQLレプリケーション@hbstudy#13
PostgreSQL開発コミュニティに参加しよう!(PostgreSQL Conference Japan 2021 発表資料)
Ad

Similar to [Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우 (20)

PDF
Indexing Complex PostgreSQL Data Types
PDF
PostgreSQL 9.4: NoSQL on ACID
PDF
2015-12-05 Александр Коротков, Иван Панченко - Слабо-структурированные данные...
PPTX
Postgres indexes: how to make them work for your application
PDF
Full Text Search in PostgreSQL
PDF
Полнотекстовый поиск в PostgreSQL / Александр Алексеев (Postgres Professional)
PDF
MySQL 5.7 NF – JSON Datatype 활용
PDF
Prefix
ODP
PostgreSQL Moscow Meetup - September 2014 - Oleg Bartunov and Alexander Korotkov
ODP
Типы данных JSONb, соответствующие индексы и модуль jsquery – Олег Бартунов, ...
PDF
Deep dive to PostgreSQL Indexes
PDF
Flexible Indexing with Postgres
 
PDF
PostgreSQL 9.6 새 기능 소개
PDF
Flexible Indexing with Postgres
 
PPTX
Postgres indexes
PPTX
PostgreSQL - It's kind've a nifty database
PPTX
50-Database Efficiency 101 Understanding and Implementing PostgreSQL Indexes....
PDF
On Beyond (PostgreSQL) Data Types
PDF
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
PDF
PG Day'14 Russia, GIN — Stronger than ever in 9.4 and further, Александр Коро...
Indexing Complex PostgreSQL Data Types
PostgreSQL 9.4: NoSQL on ACID
2015-12-05 Александр Коротков, Иван Панченко - Слабо-структурированные данные...
Postgres indexes: how to make them work for your application
Full Text Search in PostgreSQL
Полнотекстовый поиск в PostgreSQL / Александр Алексеев (Postgres Professional)
MySQL 5.7 NF – JSON Datatype 활용
Prefix
PostgreSQL Moscow Meetup - September 2014 - Oleg Bartunov and Alexander Korotkov
Типы данных JSONb, соответствующие индексы и модуль jsquery – Олег Бартунов, ...
Deep dive to PostgreSQL Indexes
Flexible Indexing with Postgres
 
PostgreSQL 9.6 새 기능 소개
Flexible Indexing with Postgres
 
Postgres indexes
PostgreSQL - It's kind've a nifty database
50-Database Efficiency 101 Understanding and Implementing PostgreSQL Indexes....
On Beyond (PostgreSQL) Data Types
Non-Relational Postgres / Bruce Momjian (EnterpriseDB)
PG Day'14 Russia, GIN — Stronger than ever in 9.4 and further, Александр Коро...
Ad

More from PgDay.Seoul (20)

PDF
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
PDF
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
PDF
[pgday.Seoul 2022] PostgreSQL with Google Cloud
PDF
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
PDF
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
PDF
[Pgday.Seoul 2020] 포스트그레스큐엘 자국어화 이야기
PDF
[Pgday.Seoul 2019] AppOS 고성능 I/O 확장 모듈로 성능 10배 향상시키기
PDF
[Pgday.Seoul 2019] Advanced FDW
PDF
[Pgday.Seoul 2018] PostgreSQL 11 새 기능 소개
PDF
[Pgday.Seoul 2018] PostgreSQL 성능을 위해 개발된 라이브러리 OS 소개 apposha
PDF
[Pgday.Seoul 2018] PostgreSQL Authentication with FreeIPA
PDF
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
PDF
[Pgday.Seoul 2018] AWS Cloud 환경에서 PostgreSQL 구축하기
PDF
[Pgday.Seoul 2018] Greenplum의 노드 분산 설계
PDF
[Pgday.Seoul 2018] replacing oracle with edb postgres
PDF
[Pgday.Seoul 2017] 5. 테드폴허브(올챙이) PostgreSQL 확장하기 - 조현종
PDF
[Pgday.Seoul 2017] 1. PostGIS의 사례로 본 PostgreSQL 확장 - 장병진
PDF
[Pgday.Seoul 2017] 4. Composite Type/JSON 파라미터를 활용한 TVP구현(with C#, JAVA) - 지현명
PDF
[Pgday.Seoul 2017] 8. PostgreSQL 10 새기능 소개 - 김상기
PDF
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
[pgday.Seoul 2022] POSTGRES 테스트코드로 기여하기 - 이동욱
[pgday.Seoul 2022] PostgreSQL with Google Cloud
[Pgday.Seoul 2021] 2. Porting Oracle UDF and Optimization
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
[Pgday.Seoul 2020] 포스트그레스큐엘 자국어화 이야기
[Pgday.Seoul 2019] AppOS 고성능 I/O 확장 모듈로 성능 10배 향상시키기
[Pgday.Seoul 2019] Advanced FDW
[Pgday.Seoul 2018] PostgreSQL 11 새 기능 소개
[Pgday.Seoul 2018] PostgreSQL 성능을 위해 개발된 라이브러리 OS 소개 apposha
[Pgday.Seoul 2018] PostgreSQL Authentication with FreeIPA
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
[Pgday.Seoul 2018] AWS Cloud 환경에서 PostgreSQL 구축하기
[Pgday.Seoul 2018] Greenplum의 노드 분산 설계
[Pgday.Seoul 2018] replacing oracle with edb postgres
[Pgday.Seoul 2017] 5. 테드폴허브(올챙이) PostgreSQL 확장하기 - 조현종
[Pgday.Seoul 2017] 1. PostGIS의 사례로 본 PostgreSQL 확장 - 장병진
[Pgday.Seoul 2017] 4. Composite Type/JSON 파라미터를 활용한 TVP구현(with C#, JAVA) - 지현명
[Pgday.Seoul 2017] 8. PostgreSQL 10 새기능 소개 - 김상기
[Pgday.Seoul 2017] 3. PostgreSQL WAL Buffers, Clog Buffers Deep Dive - 이근오

Recently uploaded (20)

PPTX
assetexplorer- product-overview - presentation
PPTX
Tech Workshop Escape Room Tech Workshop
PDF
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
PPTX
Why Generative AI is the Future of Content, Code & Creativity?
PPTX
Trending Python Topics for Data Visualization in 2025
PDF
Topaz Photo AI Crack New Download (Latest 2025)
PPTX
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
PPTX
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
PPTX
Computer Software and OS of computer science of grade 11.pptx
PDF
Types of Token_ From Utility to Security.pdf
PPTX
Weekly report ppt - harsh dattuprasad patel.pptx
DOCX
How to Use SharePoint as an ISO-Compliant Document Management System
PDF
DNT Brochure 2025 – ISV Solutions @ D365
PDF
Wondershare Recoverit Full Crack New Version (Latest 2025)
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Cost to Outsource Software Development in 2025
PDF
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025
assetexplorer- product-overview - presentation
Tech Workshop Escape Room Tech Workshop
AI-Powered Threat Modeling: The Future of Cybersecurity by Arun Kumar Elengov...
Why Generative AI is the Future of Content, Code & Creativity?
Trending Python Topics for Data Visualization in 2025
Topaz Photo AI Crack New Download (Latest 2025)
AMADEUS TRAVEL AGENT SOFTWARE | AMADEUS TICKETING SYSTEM
Embracing Complexity in Serverless! GOTO Serverless Bengaluru
Computer Software and OS of computer science of grade 11.pptx
Types of Token_ From Utility to Security.pdf
Weekly report ppt - harsh dattuprasad patel.pptx
How to Use SharePoint as an ISO-Compliant Document Management System
DNT Brochure 2025 – ISV Solutions @ D365
Wondershare Recoverit Full Crack New Version (Latest 2025)
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
AI/ML Infra Meetup | LLM Agents and Implementation Challenges
Complete Guide to Website Development in Malaysia for SMEs
Cost to Outsource Software Development in 2025
DuckDuckGo Private Browser Premium APK for Android Crack Latest 2025

[Pgday.Seoul 2017] 6. GIN vs GiST 인덱스 이야기 - 박진우

  • 1. GIN vs. GiST 인덱스 이야기 가이아쓰리디㈜ 박진우(swat018@gmail.com) 2017. 11. 04
  • 7. Index 인덱스는 지정된 컬럼에 대한 매핑 정보를 가지고 있습니다. Ex) CREATE INDEX test1_id_index ON test1 (id);
  • 8. Index PostgreSQL에서는 다음과 같은 Index type을 지원합니다. • B-Tree : numbers, text, dates, etc.. • Generalized Inverted Index (GIN) • Generalized Inverted Search Tree (GiST) • Space partitioned GiST (SP-GiST) • Block Range Indexes (BRIN) • Hash
  • 9. Heap Heap(힙) 이란? : 정렬의 기준이 없이 저장된 테이블의 존재 형태 Block 0 Block 1 Block 2 Block 3 Block 4 Block 0 Block 1 Block 2 Block 3 Block 4 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3
  • 10. Heap Block 0 Block 1 Block 2 Block 3 Block 4 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 TID: Physical location of heap tuple ex) Berlin: 0번째 Block의 2번째 항목이다. Item Point: Berlin  (0,2)
  • 11. Heap • Table file은 n개의 block으로 구성되어 있다. • 한 block 당 Page의 디폴트 크기는 8192byte(약 8KB)이다. • 한 페이지(Page)는 Header Info, Record data, free space로 구성되어 있다.
  • 12. Heap
  • 13. Seq. Scan VS. Index Scan
  • 14. B-tree Postgres=# CREATE INDEX indexname ON tablename (columnname) CREATE INDEX test1_id_index ON test1 (id); • 기본적인 Index type의 방식 • 사용법
  • 20. GIN 1. Text retrival postgres=# -- create a table with a text column postgres=# CREATE TABLE t1 (id serial, t text); CREATE TABLE postgres=# CREATE INDEX t1_idx ON t1 USING gin (to_tsvector('english', t)); CREATE INDEX postgres=# INSERT INTO t1 VALUES (1, 'a fat cat sat on a mat and ate a fat rat'); INSERT 0 1 postgres=# INSERT INTO t1 VALUES (2, 'a fat dog sat on a mat and ate a fat chop'); INSERT 0 1 postgres=# -- is there a row where column t contains the two words? (syntax contains some magic to hit index) postgres=# SELECT * FROM t1 WHERE to_tsvector('english', t) @@ to_tsquery('fat & rat'); id | t ----+------------------------------------------ 1 | a fat cat sat on a mat and ate a fat rat (1 row) postgres=# CREATE INDEX indexname ON tablename USING GIN (columnname);
  • 21. GIN 2. Array postgres=# -- create a table where one column exists of an integer array postgres=# -- postgres=# CREATE TABLE t2 (id serial, temperatures INTEGER[]); CREATE TABLE postgres=# CREATE INDEX t2_idx ON t2 USING gin (temperatures); CREATE INDEX postgres=# INSERT INTO t2 VALUES (1, '{11, 12, 13, 14}'); INSERT 0 1 postgres=# INSERT INTO t2 VALUES (2, '{21, 22, 23, 24}'); INSERT 0 1 postgres=# -- Is there a row with the two array elements 12 and 11? postgres=# SELECT * FROM t2 WHERE temperatures @> '{12, 11}'; id | temperatures ----+--------------- 1 | {11,12,13,14} (1 row)
  • 22. GiST • “contains”, “left of”, “overlaps”, 등을 지원한다. • Full Text Search, Geometric operations (PostGIS, etc. ), Handling ranges (tiem, etc.) • KNN-search, BRTree를 바탕으로 구성되어 있다.
  • 27. GiST postgres=# CREATE INDEX indexname ON tablename USING GIST (columnname); postgres=# -- create a table with a column of non-trivial type postgres=# -- postgres=# CREATE TABLE t3 (id serial, c circle); CREATE TABLE postgres=# CREATE INDEX t3_idx ON t3 USING gist(c); CREATE INDEX postgres=# INSERT INTO t3 VALUES (1, circle '((0, 0), 0.5)'); INSERT 0 1 postgres=# INSERT INTO t3 VALUES (2, circle '((1, 0), 0.5)'); INSERT 0 1 postgres=# INSERT INTO t3 VALUES (3, circle '((0.3, 0.3), 0.3)'); INSERT 0 1 postgres=# -- which circles lie in the bounds of the unit circle? postgres=# SELECT * FROM t3 WHERE circle '((0, 0), 1)' @> c; id | c ----+----------------- 1 | <(0,0),0.5> 3 | <(0.3,0.3),0.3> (2 rows)
  • 31. summary • B-tree is ideal for unique values • GIN is ideal for indexes with many duplicates • GIST for everything else Experiments lead to the following observations: creation time - GIN takes 3x time to build than GiST size of index - GIN is 2-3 times bigger than GiST search time - GIN is 3 times faster than GiST update time - GIN is about 10 times slower than GiST