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 2022] PostgreSQL구조 - 윤성재
PgDay.Seoul
 
PDF
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
PgDay.Seoul
 
PDF
PostgreSQL Deep Internal
EXEM
 
PDF
[Pgday.Seoul 2020] SQL Tuning
PgDay.Seoul
 
PDF
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
PgDay.Seoul
 
PPTX
MySQL_MariaDB로의_전환_기술요소-202212.pptx
NeoClova
 
PDF
Mastering PostgreSQL Administration
EDB
 
PDF
[Pgday.Seoul 2017] 7. PostgreSQL DB Tuning 기업사례 - 송춘자
PgDay.Seoul
 
[pgday.Seoul 2022] PostgreSQL구조 - 윤성재
PgDay.Seoul
 
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
PgDay.Seoul
 
PostgreSQL Deep Internal
EXEM
 
[Pgday.Seoul 2020] SQL Tuning
PgDay.Seoul
 
[pgday.Seoul 2022] 서비스개편시 PostgreSQL 도입기 - 진소린 & 김태정
PgDay.Seoul
 
MySQL_MariaDB로의_전환_기술요소-202212.pptx
NeoClova
 
Mastering PostgreSQL Administration
EDB
 
[Pgday.Seoul 2017] 7. PostgreSQL DB Tuning 기업사례 - 송춘자
PgDay.Seoul
 

What's hot (20)

PDF
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
PgDay.Seoul
 
PDF
[Pgday.Seoul 2017] 8. PostgreSQL 10 새기능 소개 - 김상기
PgDay.Seoul
 
PDF
Patroni - HA PostgreSQL made easy
Alexander Kukushkin
 
PDF
Mvcc in postgreSQL 권건우
PgDay.Seoul
 
PDF
Amazon Redshift의 이해와 활용 (김용우) - AWS DB Day
Amazon Web Services Korea
 
PDF
Pgday bdr 천정대
PgDay.Seoul
 
PDF
How to Use JSON in MySQL Wrong
Karwin Software Solutions LLC
 
PDF
InnoDB Locking Explained with Stick Figures
Karwin Software Solutions LLC
 
ODP
OpenGurukul : Database : PostgreSQL
Open Gurukul
 
PDF
redis 소개자료 - 네오클로바
NeoClova
 
PPTX
Indexing with MongoDB
MongoDB
 
PPTX
검색엔진이 데이터를 다루는 법 김종민
종민 김
 
PDF
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
Amazon Web Services Korea
 
PDF
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
PDF
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
PgDay.Seoul
 
PDF
[236] 카카오의데이터파이프라인 윤도영
NAVER D2
 
PDF
Extensible Data Modeling
Karwin Software Solutions LLC
 
PDF
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
Ji-Woong Choi
 
PDF
PostgreSQL 공간관리 살펴보기 이근오
PgDay.Seoul
 
PDF
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Altinity Ltd
 
[Pgday.Seoul 2021] 1. 예제로 살펴보는 포스트그레스큐엘의 독특한 SQL
PgDay.Seoul
 
[Pgday.Seoul 2017] 8. PostgreSQL 10 새기능 소개 - 김상기
PgDay.Seoul
 
Patroni - HA PostgreSQL made easy
Alexander Kukushkin
 
Mvcc in postgreSQL 권건우
PgDay.Seoul
 
Amazon Redshift의 이해와 활용 (김용우) - AWS DB Day
Amazon Web Services Korea
 
Pgday bdr 천정대
PgDay.Seoul
 
How to Use JSON in MySQL Wrong
Karwin Software Solutions LLC
 
InnoDB Locking Explained with Stick Figures
Karwin Software Solutions LLC
 
OpenGurukul : Database : PostgreSQL
Open Gurukul
 
redis 소개자료 - 네오클로바
NeoClova
 
Indexing with MongoDB
MongoDB
 
검색엔진이 데이터를 다루는 법 김종민
종민 김
 
마이크로서비스 기반 클라우드 아키텍처 구성 모범 사례 - 윤석찬 (AWS 테크에반젤리스트)
Amazon Web Services Korea
 
Deep dive into PostgreSQL statistics.
Alexey Lesovsky
 
[Pgday.Seoul 2018] 이기종 DB에서 PostgreSQL로의 Migration을 위한 DB2PG
PgDay.Seoul
 
[236] 카카오의데이터파이프라인 윤도영
NAVER D2
 
Extensible Data Modeling
Karwin Software Solutions LLC
 
[오픈소스컨설팅]쿠버네티스를 활용한 개발환경 구축
Ji-Woong Choi
 
PostgreSQL 공간관리 살펴보기 이근오
PgDay.Seoul
 
Deep Dive on ClickHouse Sharding and Replication-2202-09-22.pdf
Altinity Ltd
 
Ad

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

PDF
Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...
Ontico
 
PDF
Postgres can do THAT?
alexbrasetvik
 
PDF
PG Day'14 Russia, GIN — Stronger than ever in 9.4 and further, Александр Коро...
pgdayrussia
 
PPT
Indexing
Davood Barfeh
 
PDF
Deep dive to PostgreSQL Indexes
Ibrar Ahmed
 
PPTX
Queuing Sql Server: Utilise queues to increase performance in SQL Server
Niels Berglund
 
PPT
Indexing & query optimization
Jared Rosoff
 
PDF
2015-12-05 Александр Коротков, Иван Панченко - Слабо-структурированные данные...
HappyDev
 
PPT
Algorithm
sultanarun
 
PPT
C++ Arrays
أحمد محمد
 
PPT
C++ Arrays
أحمد محمد
 
PDF
Bineary_Search Bineary_Search.pdf Bineary_Search.pdf
MasihiZindagi
 
PDF
The NoSQL store everyone ignored
Zohaib Hassan
 
PPTX
Chapter 3 Built-in Data Structures, Functions, and Files .pptx
SovannDoeur
 
ODP
Типы данных JSONb, соответствующие индексы и модуль jsquery – Олег Бартунов, ...
Yandex
 
ODP
PostgreSQL Moscow Meetup - September 2014 - Oleg Bartunov and Alexander Korotkov
Nikolay Samokhvalov
 
PPTX
3 DS-Arrays.pptx 3 DS-Arrays.pptx 3 DS-Arrays.pptx
mohammedansaralima
 
PPTX
Database index
Riteshkiit
 
PPTX
Brixton Library Technology Initiative
Basil Bibi
 
PDF
Indexing Complex PostgreSQL Data Types
Jonathan Katz
 
Полнотекстовый поиск в PostgreSQL за миллисекунды (Олег Бартунов, Александр К...
Ontico
 
Postgres can do THAT?
alexbrasetvik
 
PG Day'14 Russia, GIN — Stronger than ever in 9.4 and further, Александр Коро...
pgdayrussia
 
Indexing
Davood Barfeh
 
Deep dive to PostgreSQL Indexes
Ibrar Ahmed
 
Queuing Sql Server: Utilise queues to increase performance in SQL Server
Niels Berglund
 
Indexing & query optimization
Jared Rosoff
 
2015-12-05 Александр Коротков, Иван Панченко - Слабо-структурированные данные...
HappyDev
 
Algorithm
sultanarun
 
C++ Arrays
أحمد محمد
 
C++ Arrays
أحمد محمد
 
Bineary_Search Bineary_Search.pdf Bineary_Search.pdf
MasihiZindagi
 
The NoSQL store everyone ignored
Zohaib Hassan
 
Chapter 3 Built-in Data Structures, Functions, and Files .pptx
SovannDoeur
 
Типы данных JSONb, соответствующие индексы и модуль jsquery – Олег Бартунов, ...
Yandex
 
PostgreSQL Moscow Meetup - September 2014 - Oleg Bartunov and Alexander Korotkov
Nikolay Samokhvalov
 
3 DS-Arrays.pptx 3 DS-Arrays.pptx 3 DS-Arrays.pptx
mohammedansaralima
 
Database index
Riteshkiit
 
Brixton Library Technology Initiative
Basil Bibi
 
Indexing Complex PostgreSQL Data Types
Jonathan Katz
 
Ad

More from PgDay.Seoul (20)

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

Recently uploaded (20)

PDF
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
PDF
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
PDF
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
PDF
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
PDF
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
PDF
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
PPTX
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
PPTX
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
PDF
Exploring AI Agents in Process Industries
amoreira6
 
PDF
Bandai Playdia The Book - David Glotz
BluePanther6
 
PDF
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
PPTX
Presentation about Database and Database Administrator
abhishekchauhan86963
 
PPTX
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
PPTX
Presentation about variables and constant.pptx
safalsingh810
 
PDF
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
PPTX
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
PDF
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
PDF
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
PPTX
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 
Salesforce Implementation Services Provider.pdf
VALiNTRY360
 
49785682629390197565_LRN3014_Migrating_the_Beast.pdf
Abilash868456
 
WatchTraderHub - Watch Dealer software with inventory management and multi-ch...
WatchDealer Pavel
 
Key Features to Look for in Arizona App Development Services
Net-Craft.com
 
On Software Engineers' Productivity - Beyond Misleading Metrics
Romén Rodríguez-Gil
 
lesson-2-rules-of-netiquette.pdf.bshhsjdj
jasmenrojas249
 
TRAVEL APIs | WHITE LABEL TRAVEL API | TOP TRAVEL APIs
philipnathen82
 
The-Dawn-of-AI-Reshaping-Our-World.pptxx
parthbhanushali307
 
Exploring AI Agents in Process Industries
amoreira6
 
Bandai Playdia The Book - David Glotz
BluePanther6
 
Using licensed Data Loss Prevention (DLP) as a strategic proactive data secur...
Q-Advise
 
Presentation about Database and Database Administrator
abhishekchauhan86963
 
Visualising Data with Scatterplots in IBM SPSS Statistics.pptx
Version 1 Analytics
 
ASSIGNMENT_1[1][1][1][1][1] (1) variables.pptx
kr2589474
 
Presentation about variables and constant.pptx
safalsingh810
 
Enhancing Healthcare RPM Platforms with Contextual AI Integration
Cadabra Studio
 
ConcordeApp: Engineering Global Impact & Unlocking Billions in Event ROI with AI
chastechaste14
 
ChatPharo: an Open Architecture for Understanding How to Talk Live to LLMs
ESUG
 
MiniTool Power Data Recovery Crack New Pre Activated Version Latest 2025
imang66g
 
Odoo Integration Services by Candidroot Solutions
CandidRoot Solutions Private Limited
 

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