SlideShare a Scribd company logo
Введение в
современную
PostgreSQL.
Часть 2
ДЕНИС ПИРШТУК,
INDATA LABS
SLONIK
ТИПЫ ИНДЕКСОВ
postgres=# select amname from pg_catalog.pg_am;
• btree ― balanced tree (по умолчанию)
• hash
• gist ― generalized search tree
• gin ― generalized inverted index
• spgist ― space-partitioned GiST
• brin ― block range index
2
http://www.postgresql.org/docs/9.1/static/textsearch-indexes.html
СХЕМА ТАБЛИЦЫ GITHUB_EVENTS
Column | Type | Modifiers | Storage | Stats target | Description
--------------+-----------------------------+-----------+----------+--------------+------------
event_id | bigint | | plain | |
event_type | text | | extended | |
event_public | boolean | | plain | |
repo_id | bigint | | plain | |
payload | jsonb | | extended | |
repo | jsonb | | extended | |
actor | jsonb | | extended | |
org | jsonb | | extended | |
created_at | timestamp without time zone | | plain | |
3
СОЗДАНИЕ ИНДЕКСА
CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ]
[ [ IF NOT EXISTS ] name ] ON table_name [ USING method ]
( { column_name | ( expression ) } [ COLLATE collation ]
[ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ]
[, ...] ) [ WITH ( storage_parameter = value [, ... ] ) ]
[ TABLESPACE tablespace_name ] [ WHERE predicate ]
4
ВЫБОРКА БЕЗ ИНДЕКСА
meetup_demo=# EXPLAIN ANALYZE SELECT repo_id FROM github_events
WHERE 3488850707 < event_id AND event_id < 3488880707;
------------------------------------------------------------------
Seq Scan on github_events (cost=0.00..265213.33 rows=13185
width=8) (actual time=0.008..495.324 rows=12982 loops=1)
Filter: (('3488850707'::bigint < event_id) AND (event_id <
'3488880707'::bigint))
Rows Removed by Filter: 2040200
Planning time: 0.189 ms
Execution time: 504.053 ms
5
ПРОСТОЙ ИНДЕКС
CREATE UNIQUE INDEX event_id_idx ON github_events(event_id);
meetup_demo=# EXPLAIN ANALYZE SELECT repo_id FROM github_events
WHERE 3488850707 < event_id AND event_id < 3488880707;
------------------------------------------------------------------
Index Scan using event_id_idx on github_events
(cost=0.43..1921.28 rows=13187 width=8) (actual time=0.024..12.544
rows=12982 loops=1)
Index Cond: (('3488850707'::bigint < event_id) AND (event_id <
'3488880707'::bigint))
Planning time: 0.190 ms
Execution time: 21.130 ms
6
ОБЫЧНЫЙ ИНДЕКС
CREATE UNIQUE INDEX event_id_idx ON github_events(event_id);
--------------------------------
Index Scan using event_id_idx on github_events
(cost=0.43..1921.28 rows=13187 width=8) (actual
time=0.037..12.485 rows=12982 loops=1)
Index Cond: (('3488850707'::bigint < event_id) AND
(event_id < '3488880707'::bigint))
Planning time: 0.186 ms
Execution time: 21.222 ms
7
СОСТАВНОЙ ИНДЕКС
CREATE UNIQUE INDEX event_id_idx
ON github_events(event_id, repo_id);
8
ПОКРЫВАЮЩИЙ ИНДЕКС
• Меньше размер индекса
• Меньше издержек на обновление
• Быстрее планирование и поиск
• Для включенных столбцов не нужен opclass
• Фильтр по включенным столбцам
CREATE UNIQUE INDEX event_id_idx2 ON
github_events(event_id) INCLUDING (repo_id);
https://pgconf.ru/media/2016/02/19/4_Lubennikova_B-
tree_pgconf.ru_3.0%20(1).pdf
9
ПОКРЫВАЮЩИЙ ИНДЕКС
meetup_demo=# EXPLAIN ANALYZE SELECT repo_id FROM
github_events WHERE 3488850707 < event_id AND event_id < 3488880707;
---------------------------------------
Index Only Scan using event_id_idx2 on github_events
(cost=0.43..23764.29 rows=13187 width=8) (actual time=0.032..12.533
rows=12982 loops=1)
Index Cond: ((event_id > '3488850707'::bigint) AND (event_id <
'3488880707'::bigint))
Heap Fetches: 12982
Planning time: 0.178 ms
Execution time: 21.147 ms
10
BRIN-ИНДЕКС
CREATE INDEX event_id_brin_idx ON github_event USING(event_id);
--------------------------------
Bitmap Heap Scan on github_events (cost=175.16..42679.52 rows=13187 width=8) (actual
time=0.824..1
5.489 rows=12982 loops=1)
Recheck Cond: (('3488850707'::bigint < event_id) AND (event_id < '3488880707'::bigint))
Rows Removed by Index Recheck: 13995
Heap Blocks: lossy=3072
-> Bitmap Index Scan on event_id_brin_idx (cost=0.00..171.87 rows=13187 width=0) (actual
time=0
.698..0.698 rows=30720 loops=1)
Index Cond: (('3488850707'::bigint < event_id) AND (event_id < '3488880707'::bigint))
Planning time: 0.094 ms
Execution time: 24.421 ms
11
РАЗНИЦА?
Размер:
Обычный: 44 MB
BRIN: 80kB
ЦЕНА ОБНОВЛЕНИЯ???
12
CSTORE_FDW
• Inspired by Optimized Row Columnar (ORC) format
developed by Hortonworks.
• Compression: Reduces in-memory and on-disk data size
by 2-4x. Can be extended to support different codecs.
• Column projections: Only reads column data relevant to
the query. Improves performance for I/O bound queries.
• Skip indexes: Stores min/max statistics for row groups,
and uses them to skip over unrelated rows.
13
CSTORE_FDW
CREATE FOREIGN TABLE cstored_github_events (
event_id bigint,
event_type text,
event_public boolean,
repo_id bigint,
payload jsonb,
repo jsonb, actor jsonb,
org jsonb,
created_at timestamp
)
SERVER cstore_server
OPTIONS(compression 'pglz');
INSERT INTO cstored_github_events (SELECT * FROM github_events);
ANALYZE cstored_github_events;
14
ТИПИЧНЫЙ ЗАПРОС
meetup_demo=# EXPLAIN ANALYZE SELECT repo_id, count(*) FROM cstored_github_events WHERE created_at BETWEEN timestamp
'2016-01-02 01:00:00' AND timestamp '2016-01-02 23:00:00' GROUP BY repo_id ORDER BY 2 DESC;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------
Sort (cost=75153.59..75221.43 rows=27137 width=8) (actual time=950.085..1030.283 rows=106145 loops=1)
Sort Key: (count(*)) DESC
Sort Method: quicksort Memory: 8048kB
-> HashAggregate (cost=72883.86..73155.23 rows=27137 width=8) (actual time=772.445..861.162 rows=106145 loops=1)
Group Key: repo_id
-> Foreign Scan on cstored_github_events (cost=0.00..70810.84 rows=414603 width=8) (actual time=4.762..382.302
rows=413081 loops=1)
Filter: ((created_at >= '2016-01-02 01:00:00'::timestamp without time zone) AND (created_at <= '2016-01-02
23:00:00'::timestamp without time zone))
Rows Removed by Filter: 46919
CStore File: /var/lib/pgsql/9.5/data/cstore_fdw/18963/1236161
CStore File Size: 1475036725
Planning time: 0.126 ms
Execution time: 1109.248 ms
15
НЕ ВСЕГДА КАК В РЕКЛАМЕ
SELECT
pg_size_pretty(cstore_table_size('cstored_github_events'));
1407 MB
SELECT pg_size_pretty(pg_table_size('github_events'));
2668 MB
16
POSTGRESQL 9.5:
FOREIGN TABLE INHERITANCE
• Fast INSERT and look-ups into current table.
• Periodically move data to archive table for compression.
• Query both via main table.
• Combined row-based and columnar store
17
КЛАСТЕРИЗАЦИЯ
SELECT retweet_count FROM contest WHERE "user.id" =
13201312;
Time: 120.743 ms
CREATE INDEX user_id_post_id ON contest("user.id"
ASC, "id" DESC);
CLUSTER contest USING user_id_post_id;
VACUUM contest;
Time: 4.128 ms
18
https://github.com/reorg/pg_repack
There is
no CLUSTER statement
in the SQL standard.
bloating
ЧТО ЕЩЕ?
• UPSERT: INSERT… ON CONFLICT DO
NOTHING/UPDATE (9.5)
• Частичные индексы (9.2)
• Материализованные представления (9.3)
19
ПРОФИЛИРОВАНИЕ И DBA
• pg_stat_statements, pg_stat_activity, pg_buffercache
• https://github.com/PostgreSQL-Consulting/pg-utils
• https://github.com/ankane/pghero
• Множество полезных запросов на wiki PostgreSQL
• https://wiki.postgresql.org/wiki/Show_database_bloat
20
PG-UTILS
• query_stat_cpu_time.sql, query_stat_io_time.sql,
query_stat_rows.sql, query_stat_time.sql
• low_used_indexes
• seq_scan_tables
• table_candidates_from_ssd.sql / table_candidates_to_ssd.sql
• index_disk_activity.sql
• table_disk_activity
• table_index_write_activity.sql / table_write_activity.sql
21
JSONB
CREATE INDEX login_idx ON github_events USING btree((org->>'login'));
CREATE INDEX login_idx2 ON github_events USING gin(org jsonb_value_path_ops);
jsonb_path_value_ops
(hash(path_item_1.path_item_2. ... .path_item_n); value)
jsonb_value_path_ops
(value; bloom(path_item_1) | bloom(path_item_2) | ... | bloom(path_item_n))
22
JSQUERY
CREATE TABLE js (
id serial,
data jsonb,
CHECK (data @@ '
name IS STRING AND
similar_ids.#: IS NUMERIC AND
points.#:(x IS NUMERIC AND y IS NUMERIC)':: jsquery));
23
МАСШТАБИРУЕМОСТЬ POSTGRESQL
24
ВЕРТИКАЛЬНАЯ
(POSTGRESPRO, POWER 8)
25
НУЖНО ВЫБИРАТЬ …
26
27
ВАРИАНТЫ
28
POSTGRES-XL
29
https://habrahabr.ru/post/253017/
http://www.postgres-xl.org/overview/
16 МАШИНОК VS 1 МАШИНКА
30
31
СПАСИБО!
32

More Related Content

What's hot

Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance
Alexey Ermakov
 
Dun ddd
Dun dddDun ddd
PostgreSQL query planner's internals
PostgreSQL query planner's internalsPostgreSQL query planner's internals
PostgreSQL query planner's internals
Alexey Ermakov
 
PostgreSQL: Advanced indexing
PostgreSQL: Advanced indexingPostgreSQL: Advanced indexing
PostgreSQL: Advanced indexing
Hans-Jürgen Schönig
 
Btree. Explore the heart of PostgreSQL.
Btree. Explore the heart of PostgreSQL. Btree. Explore the heart of PostgreSQL.
Btree. Explore the heart of PostgreSQL.
Anastasia Lubennikova
 
Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)
Jonathan Katz
 
PostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major FeaturesPostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major Features
InMobi Technology
 
Ac cuda c_4
Ac cuda c_4Ac cuda c_4
Ac cuda c_4
Josh Wyatt
 
Unified Data Platform, by Pauline Yeung of Cisco Systems
Unified Data Platform, by Pauline Yeung of Cisco SystemsUnified Data Platform, by Pauline Yeung of Cisco Systems
Unified Data Platform, by Pauline Yeung of Cisco Systems
Altinity Ltd
 
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Rakib Hossain
 
Splitgraph: Open data and beyond - SF ClickHouse Meetup Sep 2020
Splitgraph: Open data and beyond - SF ClickHouse Meetup Sep 2020Splitgraph: Open data and beyond - SF ClickHouse Meetup Sep 2020
Splitgraph: Open data and beyond - SF ClickHouse Meetup Sep 2020
Altinity Ltd
 
Db2
Db2Db2
Using Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data AnalysisUsing Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data Analysis
Sveta Smirnova
 
GTC Japan 2014
GTC Japan 2014GTC Japan 2014
GTC Japan 2014
Hitoshi Sato
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
Alexey Bashtanov
 
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Altinity Ltd
 
Backup automation in KAKAO
Backup automation in KAKAO Backup automation in KAKAO
Backup automation in KAKAO
I Goo Lee
 
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlareClickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
Altinity Ltd
 
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with Galera
Sveta Smirnova
 

What's hot (20)

Mysql56 replication
Mysql56 replicationMysql56 replication
Mysql56 replication
 
Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance Using PostgreSQL statistics to optimize performance
Using PostgreSQL statistics to optimize performance
 
Dun ddd
Dun dddDun ddd
Dun ddd
 
PostgreSQL query planner's internals
PostgreSQL query planner's internalsPostgreSQL query planner's internals
PostgreSQL query planner's internals
 
PostgreSQL: Advanced indexing
PostgreSQL: Advanced indexingPostgreSQL: Advanced indexing
PostgreSQL: Advanced indexing
 
Btree. Explore the heart of PostgreSQL.
Btree. Explore the heart of PostgreSQL. Btree. Explore the heart of PostgreSQL.
Btree. Explore the heart of PostgreSQL.
 
Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)Accelerating Local Search with PostgreSQL (KNN-Search)
Accelerating Local Search with PostgreSQL (KNN-Search)
 
PostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major FeaturesPostgreSQL 9.5 - Major Features
PostgreSQL 9.5 - Major Features
 
Ac cuda c_4
Ac cuda c_4Ac cuda c_4
Ac cuda c_4
 
Unified Data Platform, by Pauline Yeung of Cisco Systems
Unified Data Platform, by Pauline Yeung of Cisco SystemsUnified Data Platform, by Pauline Yeung of Cisco Systems
Unified Data Platform, by Pauline Yeung of Cisco Systems
 
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.Exploring Parallel Merging In GPU Based Systems Using CUDA C.
Exploring Parallel Merging In GPU Based Systems Using CUDA C.
 
Splitgraph: Open data and beyond - SF ClickHouse Meetup Sep 2020
Splitgraph: Open data and beyond - SF ClickHouse Meetup Sep 2020Splitgraph: Open data and beyond - SF ClickHouse Meetup Sep 2020
Splitgraph: Open data and beyond - SF ClickHouse Meetup Sep 2020
 
Db2
Db2Db2
Db2
 
Using Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data AnalysisUsing Apache Spark and MySQL for Data Analysis
Using Apache Spark and MySQL for Data Analysis
 
GTC Japan 2014
GTC Japan 2014GTC Japan 2014
GTC Japan 2014
 
PostgreSQL and RAM usage
PostgreSQL and RAM usagePostgreSQL and RAM usage
PostgreSQL and RAM usage
 
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
Analytics at Speed: Introduction to ClickHouse and Common Use Cases. By Mikha...
 
Backup automation in KAKAO
Backup automation in KAKAO Backup automation in KAKAO
Backup automation in KAKAO
 
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlareClickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
Clickhouse Capacity Planning for OLAP Workloads, Mik Kocikowski of CloudFlare
 
How to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with GaleraHow to Avoid Pitfalls in Schema Upgrade with Galera
How to Avoid Pitfalls in Schema Upgrade with Galera
 

Viewers also liked

Gastrorelatos
GastrorelatosGastrorelatos
Gastrorelatos
Victor Gomez Romero
 
Important scene in Hamlet ( Gravedigge's scene and Nunnery scene)
Important scene in Hamlet ( Gravedigge's scene and Nunnery scene)Important scene in Hamlet ( Gravedigge's scene and Nunnery scene)
Important scene in Hamlet ( Gravedigge's scene and Nunnery scene)
Mital Raval
 
History of Swimming in Kingston
History of Swimming in KingstonHistory of Swimming in Kingston
History of Swimming in Kingston
christinegrossutti
 
Postura de la FEU ante el cobro de una segunda credencial a los estudiantes d...
Postura de la FEU ante el cobro de una segunda credencial a los estudiantes d...Postura de la FEU ante el cobro de una segunda credencial a los estudiantes d...
Postura de la FEU ante el cobro de una segunda credencial a los estudiantes d...
feudifusion
 
La salud del branding en España 2015 (II Barómetro Aebrand)
La salud del branding en España 2015 (II Barómetro Aebrand)La salud del branding en España 2015 (II Barómetro Aebrand)
La salud del branding en España 2015 (II Barómetro Aebrand)
Branward®
 
Liderazgo 1
Liderazgo 1Liderazgo 1
Liderazgo 1
Nancy Sierra
 
Kanel National Adaptation Plan Role Of Land Rights Keshav Kanel Oct 2008
Kanel National Adaptation Plan Role Of Land Rights Keshav Kanel Oct 2008Kanel National Adaptation Plan Role Of Land Rights Keshav Kanel Oct 2008
Kanel National Adaptation Plan Role Of Land Rights Keshav Kanel Oct 2008rightsandclimate
 
Lección 7 - Curso de Marketing Digital - La Web 1.0
Lección 7 - Curso de Marketing Digital - La Web 1.0Lección 7 - Curso de Marketing Digital - La Web 1.0
Lección 7 - Curso de Marketing Digital - La Web 1.0
SM Digital
 
Postmodernism presentation
Postmodernism presentationPostmodernism presentation
Postmodernism presentation
Danika Barker
 
Estudio del impacto en Twitter del #MWC16
Estudio del impacto en Twitter del #MWC16Estudio del impacto en Twitter del #MWC16
Estudio del impacto en Twitter del #MWC16
SocialBrains
 
Estudio del impacto de los Papeles de Panamá 2 meses después
Estudio del impacto de los Papeles de Panamá 2 meses despuésEstudio del impacto de los Papeles de Panamá 2 meses después
Estudio del impacto de los Papeles de Panamá 2 meses después
SocialBrains
 
vega rochat portfolio 2014
vega rochat portfolio 2014vega rochat portfolio 2014
vega rochat portfolio 2014vega rochat
 
Family paintings
Family paintingsFamily paintings
Family paintings
Lau Ra
 

Viewers also liked (15)

Face robots
Face robotsFace robots
Face robots
 
Gastrorelatos
GastrorelatosGastrorelatos
Gastrorelatos
 
Important scene in Hamlet ( Gravedigge's scene and Nunnery scene)
Important scene in Hamlet ( Gravedigge's scene and Nunnery scene)Important scene in Hamlet ( Gravedigge's scene and Nunnery scene)
Important scene in Hamlet ( Gravedigge's scene and Nunnery scene)
 
History of Swimming in Kingston
History of Swimming in KingstonHistory of Swimming in Kingston
History of Swimming in Kingston
 
Postura de la FEU ante el cobro de una segunda credencial a los estudiantes d...
Postura de la FEU ante el cobro de una segunda credencial a los estudiantes d...Postura de la FEU ante el cobro de una segunda credencial a los estudiantes d...
Postura de la FEU ante el cobro de una segunda credencial a los estudiantes d...
 
La salud del branding en España 2015 (II Barómetro Aebrand)
La salud del branding en España 2015 (II Barómetro Aebrand)La salud del branding en España 2015 (II Barómetro Aebrand)
La salud del branding en España 2015 (II Barómetro Aebrand)
 
Liderazgo 1
Liderazgo 1Liderazgo 1
Liderazgo 1
 
Kanel National Adaptation Plan Role Of Land Rights Keshav Kanel Oct 2008
Kanel National Adaptation Plan Role Of Land Rights Keshav Kanel Oct 2008Kanel National Adaptation Plan Role Of Land Rights Keshav Kanel Oct 2008
Kanel National Adaptation Plan Role Of Land Rights Keshav Kanel Oct 2008
 
Lección 7 - Curso de Marketing Digital - La Web 1.0
Lección 7 - Curso de Marketing Digital - La Web 1.0Lección 7 - Curso de Marketing Digital - La Web 1.0
Lección 7 - Curso de Marketing Digital - La Web 1.0
 
Postmodernism presentation
Postmodernism presentationPostmodernism presentation
Postmodernism presentation
 
Estudio del impacto en Twitter del #MWC16
Estudio del impacto en Twitter del #MWC16Estudio del impacto en Twitter del #MWC16
Estudio del impacto en Twitter del #MWC16
 
Estudio del impacto de los Papeles de Panamá 2 meses después
Estudio del impacto de los Papeles de Panamá 2 meses despuésEstudio del impacto de los Papeles de Panamá 2 meses después
Estudio del impacto de los Papeles de Panamá 2 meses después
 
vega rochat portfolio 2014
vega rochat portfolio 2014vega rochat portfolio 2014
vega rochat portfolio 2014
 
Family paintings
Family paintingsFamily paintings
Family paintings
 
Muysensual
MuysensualMuysensual
Muysensual
 

Similar to Введение в современную PostgreSQL. Часть 2

[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
PgDay.Seoul
 
query_tuning.pdf
query_tuning.pdfquery_tuning.pdf
query_tuning.pdf
ssuserf99076
 
New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...
Sage Computing Services
 
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
SegFaultConf
 
All you need to know about CREATE STATISTICS
All you need to know about CREATE STATISTICSAll you need to know about CREATE STATISTICS
All you need to know about CREATE STATISTICS
EDB
 
Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009
mattsmiley
 
Basic Query Tuning Primer
Basic Query Tuning PrimerBasic Query Tuning Primer
Basic Query Tuning Primer
Command Prompt., Inc
 
Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sqlj9soto
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Hemant K Chitale
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
Emily Ikuta
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012Roland Bouman
 
Explain this!
Explain this!Explain this!
Explain this!
Fabio Telles Rodriguez
 
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
MariaDB plc
 
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
MariaDB plc
 
Letgo Data Platform: A global overview
Letgo Data Platform: A global overviewLetgo Data Platform: A global overview
Letgo Data Platform: A global overview
Ricardo Fanjul Fandiño
 
Lightweight Transactions at Lightning Speed
Lightweight Transactions at Lightning SpeedLightweight Transactions at Lightning Speed
Lightweight Transactions at Lightning Speed
ScyllaDB
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
Wim Godden
 
Checking clustering factor to detect row migration
Checking clustering factor to detect row migrationChecking clustering factor to detect row migration
Checking clustering factor to detect row migration
Heribertus Bramundito
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01Karam Abuataya
 

Similar to Введение в современную PostgreSQL. Часть 2 (20)

[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
[Pgday.Seoul 2019] Citus를 이용한 분산 데이터베이스
 
query_tuning.pdf
query_tuning.pdfquery_tuning.pdf
query_tuning.pdf
 
New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...New Tuning Features in Oracle 11g - How to make your database as boring as po...
New Tuning Features in Oracle 11g - How to make your database as boring as po...
 
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
Robert Pankowecki - Czy sprzedawcy SQLowych baz nas oszukali?
 
All you need to know about CREATE STATISTICS
All you need to know about CREATE STATISTICSAll you need to know about CREATE STATISTICS
All you need to know about CREATE STATISTICS
 
Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009Basic Query Tuning Primer - Pg West 2009
Basic Query Tuning Primer - Pg West 2009
 
Basic Query Tuning Primer
Basic Query Tuning PrimerBasic Query Tuning Primer
Basic Query Tuning Primer
 
Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sql
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
 
MySQL 5.7 in a Nutshell
MySQL 5.7 in a NutshellMySQL 5.7 in a Nutshell
MySQL 5.7 in a Nutshell
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
 
Explain this!
Explain this!Explain this!
Explain this!
 
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
 
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
What's New in MariaDB Server 10.2 and MariaDB MaxScale 2.1
 
Letgo Data Platform: A global overview
Letgo Data Platform: A global overviewLetgo Data Platform: A global overview
Letgo Data Platform: A global overview
 
Lightweight Transactions at Lightning Speed
Lightweight Transactions at Lightning SpeedLightweight Transactions at Lightning Speed
Lightweight Transactions at Lightning Speed
 
Beyond php - it's not (just) about the code
Beyond php - it's not (just) about the codeBeyond php - it's not (just) about the code
Beyond php - it's not (just) about the code
 
Checking clustering factor to detect row migration
Checking clustering factor to detect row migrationChecking clustering factor to detect row migration
Checking clustering factor to detect row migration
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
 

More from Dzianis Pirshtuk

Practical machine learning: rational approach
Practical machine learning: rational approachPractical machine learning: rational approach
Practical machine learning: rational approach
Dzianis Pirshtuk
 
Machine Learning and Artificial Intelligence as a business tool and a foundat...
Machine Learning and Artificial Intelligence as a business tool and a foundat...Machine Learning and Artificial Intelligence as a business tool and a foundat...
Machine Learning and Artificial Intelligence as a business tool and a foundat...
Dzianis Pirshtuk
 
InData Labs R&D Lab Presentation
InData Labs R&D Lab PresentationInData Labs R&D Lab Presentation
InData Labs R&D Lab Presentation
Dzianis Pirshtuk
 
DataTalks #6. Погружение в науку о данных
DataTalks #6. Погружение в науку о данныхDataTalks #6. Погружение в науку о данных
DataTalks #6. Погружение в науку о данных
Dzianis Pirshtuk
 
Разработка интеллектуальных информационных систем: взгляд изнутри
Разработка интеллектуальных информационных систем: взгляд изнутриРазработка интеллектуальных информационных систем: взгляд изнутри
Разработка интеллектуальных информационных систем: взгляд изнутри
Dzianis Pirshtuk
 
Введение в современную PostgreSQL. Часть 1
Введение в современную PostgreSQL. Часть 1Введение в современную PostgreSQL. Часть 1
Введение в современную PostgreSQL. Часть 1
Dzianis Pirshtuk
 
Supervised ML in Practice: Tips & Tricks
Supervised ML in Practice:  Tips & TricksSupervised ML in Practice:  Tips & Tricks
Supervised ML in Practice: Tips & Tricks
Dzianis Pirshtuk
 

More from Dzianis Pirshtuk (7)

Practical machine learning: rational approach
Practical machine learning: rational approachPractical machine learning: rational approach
Practical machine learning: rational approach
 
Machine Learning and Artificial Intelligence as a business tool and a foundat...
Machine Learning and Artificial Intelligence as a business tool and a foundat...Machine Learning and Artificial Intelligence as a business tool and a foundat...
Machine Learning and Artificial Intelligence as a business tool and a foundat...
 
InData Labs R&D Lab Presentation
InData Labs R&D Lab PresentationInData Labs R&D Lab Presentation
InData Labs R&D Lab Presentation
 
DataTalks #6. Погружение в науку о данных
DataTalks #6. Погружение в науку о данныхDataTalks #6. Погружение в науку о данных
DataTalks #6. Погружение в науку о данных
 
Разработка интеллектуальных информационных систем: взгляд изнутри
Разработка интеллектуальных информационных систем: взгляд изнутриРазработка интеллектуальных информационных систем: взгляд изнутри
Разработка интеллектуальных информационных систем: взгляд изнутри
 
Введение в современную PostgreSQL. Часть 1
Введение в современную PostgreSQL. Часть 1Введение в современную PostgreSQL. Часть 1
Введение в современную PostgreSQL. Часть 1
 
Supervised ML in Practice: Tips & Tricks
Supervised ML in Practice:  Tips & TricksSupervised ML in Practice:  Tips & Tricks
Supervised ML in Practice: Tips & Tricks
 

Recently uploaded

AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
Aftab Hussain
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Graspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code AnalysisGraspan: A Big Data System for Big Code Analysis
Graspan: A Big Data System for Big Code Analysis
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 

Введение в современную PostgreSQL. Часть 2

  • 2. ТИПЫ ИНДЕКСОВ postgres=# select amname from pg_catalog.pg_am; • btree ― balanced tree (по умолчанию) • hash • gist ― generalized search tree • gin ― generalized inverted index • spgist ― space-partitioned GiST • brin ― block range index 2 http://www.postgresql.org/docs/9.1/static/textsearch-indexes.html
  • 3. СХЕМА ТАБЛИЦЫ GITHUB_EVENTS Column | Type | Modifiers | Storage | Stats target | Description --------------+-----------------------------+-----------+----------+--------------+------------ event_id | bigint | | plain | | event_type | text | | extended | | event_public | boolean | | plain | | repo_id | bigint | | plain | | payload | jsonb | | extended | | repo | jsonb | | extended | | actor | jsonb | | extended | | org | jsonb | | extended | | created_at | timestamp without time zone | | plain | | 3
  • 4. СОЗДАНИЕ ИНДЕКСА CREATE [ UNIQUE ] INDEX [ CONCURRENTLY ] [ [ IF NOT EXISTS ] name ] ON table_name [ USING method ] ( { column_name | ( expression ) } [ COLLATE collation ] [ opclass ] [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [, ...] ) [ WITH ( storage_parameter = value [, ... ] ) ] [ TABLESPACE tablespace_name ] [ WHERE predicate ] 4
  • 5. ВЫБОРКА БЕЗ ИНДЕКСА meetup_demo=# EXPLAIN ANALYZE SELECT repo_id FROM github_events WHERE 3488850707 < event_id AND event_id < 3488880707; ------------------------------------------------------------------ Seq Scan on github_events (cost=0.00..265213.33 rows=13185 width=8) (actual time=0.008..495.324 rows=12982 loops=1) Filter: (('3488850707'::bigint < event_id) AND (event_id < '3488880707'::bigint)) Rows Removed by Filter: 2040200 Planning time: 0.189 ms Execution time: 504.053 ms 5
  • 6. ПРОСТОЙ ИНДЕКС CREATE UNIQUE INDEX event_id_idx ON github_events(event_id); meetup_demo=# EXPLAIN ANALYZE SELECT repo_id FROM github_events WHERE 3488850707 < event_id AND event_id < 3488880707; ------------------------------------------------------------------ Index Scan using event_id_idx on github_events (cost=0.43..1921.28 rows=13187 width=8) (actual time=0.024..12.544 rows=12982 loops=1) Index Cond: (('3488850707'::bigint < event_id) AND (event_id < '3488880707'::bigint)) Planning time: 0.190 ms Execution time: 21.130 ms 6
  • 7. ОБЫЧНЫЙ ИНДЕКС CREATE UNIQUE INDEX event_id_idx ON github_events(event_id); -------------------------------- Index Scan using event_id_idx on github_events (cost=0.43..1921.28 rows=13187 width=8) (actual time=0.037..12.485 rows=12982 loops=1) Index Cond: (('3488850707'::bigint < event_id) AND (event_id < '3488880707'::bigint)) Planning time: 0.186 ms Execution time: 21.222 ms 7
  • 8. СОСТАВНОЙ ИНДЕКС CREATE UNIQUE INDEX event_id_idx ON github_events(event_id, repo_id); 8
  • 9. ПОКРЫВАЮЩИЙ ИНДЕКС • Меньше размер индекса • Меньше издержек на обновление • Быстрее планирование и поиск • Для включенных столбцов не нужен opclass • Фильтр по включенным столбцам CREATE UNIQUE INDEX event_id_idx2 ON github_events(event_id) INCLUDING (repo_id); https://pgconf.ru/media/2016/02/19/4_Lubennikova_B- tree_pgconf.ru_3.0%20(1).pdf 9
  • 10. ПОКРЫВАЮЩИЙ ИНДЕКС meetup_demo=# EXPLAIN ANALYZE SELECT repo_id FROM github_events WHERE 3488850707 < event_id AND event_id < 3488880707; --------------------------------------- Index Only Scan using event_id_idx2 on github_events (cost=0.43..23764.29 rows=13187 width=8) (actual time=0.032..12.533 rows=12982 loops=1) Index Cond: ((event_id > '3488850707'::bigint) AND (event_id < '3488880707'::bigint)) Heap Fetches: 12982 Planning time: 0.178 ms Execution time: 21.147 ms 10
  • 11. BRIN-ИНДЕКС CREATE INDEX event_id_brin_idx ON github_event USING(event_id); -------------------------------- Bitmap Heap Scan on github_events (cost=175.16..42679.52 rows=13187 width=8) (actual time=0.824..1 5.489 rows=12982 loops=1) Recheck Cond: (('3488850707'::bigint < event_id) AND (event_id < '3488880707'::bigint)) Rows Removed by Index Recheck: 13995 Heap Blocks: lossy=3072 -> Bitmap Index Scan on event_id_brin_idx (cost=0.00..171.87 rows=13187 width=0) (actual time=0 .698..0.698 rows=30720 loops=1) Index Cond: (('3488850707'::bigint < event_id) AND (event_id < '3488880707'::bigint)) Planning time: 0.094 ms Execution time: 24.421 ms 11
  • 12. РАЗНИЦА? Размер: Обычный: 44 MB BRIN: 80kB ЦЕНА ОБНОВЛЕНИЯ??? 12
  • 13. CSTORE_FDW • Inspired by Optimized Row Columnar (ORC) format developed by Hortonworks. • Compression: Reduces in-memory and on-disk data size by 2-4x. Can be extended to support different codecs. • Column projections: Only reads column data relevant to the query. Improves performance for I/O bound queries. • Skip indexes: Stores min/max statistics for row groups, and uses them to skip over unrelated rows. 13
  • 14. CSTORE_FDW CREATE FOREIGN TABLE cstored_github_events ( event_id bigint, event_type text, event_public boolean, repo_id bigint, payload jsonb, repo jsonb, actor jsonb, org jsonb, created_at timestamp ) SERVER cstore_server OPTIONS(compression 'pglz'); INSERT INTO cstored_github_events (SELECT * FROM github_events); ANALYZE cstored_github_events; 14
  • 15. ТИПИЧНЫЙ ЗАПРОС meetup_demo=# EXPLAIN ANALYZE SELECT repo_id, count(*) FROM cstored_github_events WHERE created_at BETWEEN timestamp '2016-01-02 01:00:00' AND timestamp '2016-01-02 23:00:00' GROUP BY repo_id ORDER BY 2 DESC; QUERY PLAN ------------------------------------------------------------------------------------------------------------------------------ Sort (cost=75153.59..75221.43 rows=27137 width=8) (actual time=950.085..1030.283 rows=106145 loops=1) Sort Key: (count(*)) DESC Sort Method: quicksort Memory: 8048kB -> HashAggregate (cost=72883.86..73155.23 rows=27137 width=8) (actual time=772.445..861.162 rows=106145 loops=1) Group Key: repo_id -> Foreign Scan on cstored_github_events (cost=0.00..70810.84 rows=414603 width=8) (actual time=4.762..382.302 rows=413081 loops=1) Filter: ((created_at >= '2016-01-02 01:00:00'::timestamp without time zone) AND (created_at <= '2016-01-02 23:00:00'::timestamp without time zone)) Rows Removed by Filter: 46919 CStore File: /var/lib/pgsql/9.5/data/cstore_fdw/18963/1236161 CStore File Size: 1475036725 Planning time: 0.126 ms Execution time: 1109.248 ms 15
  • 16. НЕ ВСЕГДА КАК В РЕКЛАМЕ SELECT pg_size_pretty(cstore_table_size('cstored_github_events')); 1407 MB SELECT pg_size_pretty(pg_table_size('github_events')); 2668 MB 16
  • 17. POSTGRESQL 9.5: FOREIGN TABLE INHERITANCE • Fast INSERT and look-ups into current table. • Periodically move data to archive table for compression. • Query both via main table. • Combined row-based and columnar store 17
  • 18. КЛАСТЕРИЗАЦИЯ SELECT retweet_count FROM contest WHERE "user.id" = 13201312; Time: 120.743 ms CREATE INDEX user_id_post_id ON contest("user.id" ASC, "id" DESC); CLUSTER contest USING user_id_post_id; VACUUM contest; Time: 4.128 ms 18 https://github.com/reorg/pg_repack There is no CLUSTER statement in the SQL standard. bloating
  • 19. ЧТО ЕЩЕ? • UPSERT: INSERT… ON CONFLICT DO NOTHING/UPDATE (9.5) • Частичные индексы (9.2) • Материализованные представления (9.3) 19
  • 20. ПРОФИЛИРОВАНИЕ И DBA • pg_stat_statements, pg_stat_activity, pg_buffercache • https://github.com/PostgreSQL-Consulting/pg-utils • https://github.com/ankane/pghero • Множество полезных запросов на wiki PostgreSQL • https://wiki.postgresql.org/wiki/Show_database_bloat 20
  • 21. PG-UTILS • query_stat_cpu_time.sql, query_stat_io_time.sql, query_stat_rows.sql, query_stat_time.sql • low_used_indexes • seq_scan_tables • table_candidates_from_ssd.sql / table_candidates_to_ssd.sql • index_disk_activity.sql • table_disk_activity • table_index_write_activity.sql / table_write_activity.sql 21
  • 22. JSONB CREATE INDEX login_idx ON github_events USING btree((org->>'login')); CREATE INDEX login_idx2 ON github_events USING gin(org jsonb_value_path_ops); jsonb_path_value_ops (hash(path_item_1.path_item_2. ... .path_item_n); value) jsonb_value_path_ops (value; bloom(path_item_1) | bloom(path_item_2) | ... | bloom(path_item_n)) 22
  • 23. JSQUERY CREATE TABLE js ( id serial, data jsonb, CHECK (data @@ ' name IS STRING AND similar_ids.#: IS NUMERIC AND points.#:(x IS NUMERIC AND y IS NUMERIC)':: jsquery)); 23
  • 27. 27
  • 30. 16 МАШИНОК VS 1 МАШИНКА 30
  • 31. 31