SlideShare una empresa de Scribd logo
1 de 32
Descargar para leer sin conexión
Введение в
современную
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

Más contenido relacionado

La actualidad más candente

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
 

La actualidad más candente (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
 

Destacado

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
rightsandclimate
 
vega rochat portfolio 2014
vega rochat portfolio 2014vega rochat portfolio 2014
vega rochat portfolio 2014
vega rochat
 

Destacado (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 a Введение в современную PostgreSQL. Часть 2

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
 
Writing efficient sql
Writing efficient sqlWriting efficient sql
Writing efficient sql
j9soto
 
Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)Oracle Diagnostics : Explain Plans (Simple)
Oracle Diagnostics : Explain Plans (Simple)
Hemant K Chitale
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
Common schema my sql uc 2012
Common schema   my sql uc 2012Common schema   my sql uc 2012
Common schema my sql uc 2012
Roland Bouman
 
11thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp0111thingsabout11g 12659705398222 Phpapp01
11thingsabout11g 12659705398222 Phpapp01
Karam Abuataya
 

Similar a Введение в современную 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
 

Más de Dzianis Pirshtuk

Más de 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
 

Último

introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
VishalKumarJha10
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdfintroduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
introduction-to-automotive Andoid os-csimmonds-ndctechtown-2021.pdf
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Введение в современную 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