SlideShare ist ein Scribd-Unternehmen logo
1 von 34
Downloaden Sie, um offline zu lesen
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN indexes on
geospatial
databases
www.2ndquadrant.com
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
~$ whoami~$ whoami
Giuseppe Broccolo, PhDGiuseppe Broccolo, PhD
PostgreSQL & PostGIS consultantPostgreSQL & PostGIS consultant
@giubro gbroccolo7
giuseppe.broccolo@2ndquadrant.it
gbroccolo gemini__81
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
Indexes & PostgreSQLIndexes & PostgreSQL
• Binary structures on disc:
– Indexing organised in nodes into 8kB pages
– Speed up data access: ~O(log N)
– High performance until the index can be contained in RAM
• Size: ~O(N)
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
Geospatial indexes in PostgreSQLGeospatial indexes in PostgreSQL
• All datatypes can be indexed in principle...
– ...just define the needed OpClass!
• Operators & Support functions
• Geospatial data can be larger than 8kB
– A single node cannot be contained into a single page
– GiST indexing allows to reduce the information that has to be
indexed compressing the PostgreSQL in-core geospatial objects
into its bounding box
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
PostGIS datatypesPostGIS datatypes
In PostGIS (since v0.6) geometry/geography are
converted into their float-precision bounding boxes
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
PostGIS datatypesPostGIS datatypes
In PostGIS (since v0.6) geometry/geography are
converted into their float-precision bounding boxes
gidx/box2df are then used as storage
datatype to populate the index’s nodes
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
GIS & BigDataGIS & BigData
LiDAR surveys
Maps of entire countries
It’s relatively easy to have to work with terabytes of geospatial data…
...can indexes be contained in RAM?
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
A new index: Block Range INdexingA new index: Block Range INdexing
– BLOCKBLOCK: set of physically adjacent 8kB pages
– RANGERANGE: boundaries of data contained in the block
– granularitygranularity: pages_per_range
• default: blocks of 128 pages
CREATE INDEX idx ON table USING brin(column) WITH (pages_per_range=10);
8kB8kB8kB8kB
S. Riggs, A. Herrera
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN - indexingBRIN - indexing
8kB8kB8kB8kB
range range range range
8kB8kB8kB8kB
8kB8kB8kB8kB
8kB8kB8kB8kB
c da b
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN - indexingBRIN - indexing
8kB8kB8kB8kB
range range range range
8kB8kB8kB8kB
8kB8kB8kB8kB
8kB8kB8kB8kB
c da b
a
b c
d
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN – scan executionBRIN – scan execution
8kB8kB8kB8kB
8kB8kB8kB8kB
8kB8kB8kB8kB
8kB8kB8kB8kB
c da b
...WHERE col<val1 AND col>val2;
BitMapIndexScan
a
b c
d
0
0
0
0
0
1
1
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN – scan executionBRIN – scan execution
8kB8kB8kB8kB
8kB8kB8kB8kB
8kB8kB8kB8kB
8kB8kB8kB8kB
c da b
...WHERE col<val1 AND col>val2;
BitMapHeapScan
a
b c
d
0
0
0
0
0
1
1
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN – scan executionBRIN – scan execution
8kB8kB8kB8kB
8kB8kB8kB8kB
...WHERE col<val1 AND col>val2;
“ordered” TidScan
(recheck cond)
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN – an example of execution planBRIN – an example of execution plan
QUERY PLAN
------------------------------------------------------------------
-> Bitmap Heap Scan on column (cost=113.50..26741.01 rows=10000
width=20) (actual time=6.513..3094.020 rows=2499193 loops=1)
Recheck Cond: column = value
Rows Removed by Index Recheck: 7500807
Heap Blocks: lossy=63695
-> Bitmap Index Scan on brin_index (cost=0.00..111.00 rows=10000
width=0) (actual time=6.200..6.200 rows=637440 loops=1)
Index Cond: column = value
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN support and extensibilityBRIN support and extensibility
• Two kind of support functions required in the OpClass:
– minmax key values are added following sorting criteria +
sorting operators
– inclusion key values are added following inclusion criteria +
inclusion operators
– No kNN support currently available!
• Extensibility
– provide support functions + operators to define the OpClass
http://www.postgresql.org/docs/9.5/static/brin-extensibility.html
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN support for PostGISBRIN support for PostGIS
https://github.com/dalibo/postgis/tree/for_upstream
Julien RouhaudRonan Dunklau me
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
BRIN support for PostGISBRIN support for PostGIS
NO kNN SUPPORT!!
– Different OpClass (inclusion support) for
• 2D (default), 3D, 4D geometry
• geography
• box2d/box3d (cross-operators defined in the OpFamily)
– Storage datatype: float-precision (such as in GiST)
• gidx (3D, 4D geometry)
• box2df (2D geometry, geography)
– brin_inclusion_add_value() has been redefined
– Operators: &&, @, ~ (2D) - &&& (3D, 4D)
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
Now it’s time to test our patch!Now it’s time to test our patch!
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
11stst
example: “sorted”example: “sorted” geometrygeometry pointspoints
~10M, 3D, SRID=0, distribution range: 0á100kunits
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
11stst
example: “sorted”example: “sorted” geometrygeometry pointspoints
~10M, 3D, SRID=0, distribution range: 0á100kunits
=# CREATE INDEX idx_gist ON points USING gist
-# (geom gist_geometry_ops_nd);
=# CREATE INDEX idx_brin_128 ON points USING brin
-# (geom brin_geometry_inclusion_ops_3d);
=# CREATE INDEX idx_brin_10 ON points USING brin
-# (geom brin_geometry_inclusion_ops_3d)
-# WITH (pages_per_range=10);
BRIN(128)/GiST 1/2000
BRIN(10)/GiST 1/1000
BRIN(128)/GiST 1/30
BRIN(10)/GiST 1/20
Sizes
Building
times
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
11stst
example: “sorted”example: “sorted” geometrygeometry pointspoints
~10M, 3D, SRID=0, distribution range: 0á100kunits
=# SELECT * FROM points
-# WHERE ‘BOX3D(10. 10. 10., 12., 12., 12.)’::box3d &&& geom;
BRIN(128)/GiST 50/1
BRIN(10)/GiST 6/1
BRIN(128)/SeqScan 1/60
BRIN(10)/SeqScan 1/350
Execution times
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
22ndnd
example: “unsorted”example: “unsorted” geometrygeometry pointspoints
~10M, 3D, SRID=0, distribution range: 0á100kunits
=# CREATE TABLE unsorted_points AS
-# SELECT * FROM points ORDER BY random();
=# SELECT * FROM unsorted_points
-# WHERE ‘BOX3D(10. 10. 10., 12., 12., 12.)’::box3d &&& geom;
BRIN(128)/GiST 2800/1
BRIN(10)/GiST 400/1
BRIN(128)/SeqScan 1/1
BRIN(10)/SeqScan 1/12
Execution times
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
22ndnd
example: “unsorted”example: “unsorted” geometrygeometry pointspoints
=# CREATE EXTENSION pageinspect;
=# SELECT blknum, value FROM brin_page_items(get_raw_page('idx_brin_128', 2), 'idx_brin_128')
-# LIMIT 5;
blknum | value
--------+------------------------------------------------------------------------
0 | {GIDX( 1.11394846439 1.64980053902 1.11335003376, 99982.2578125 99982.640625
99982.1171875 ) .. f .. f}
128 | {GIDX( 0.224781364202 0.184096381068 0.798862099648, 99995.859375 99995.171875
99995.0390625 ) .. f .. f}
256 | {GIDX( 6.25802087784 6.50119876862 6.8031873703, 99993.15625 99993.8203125
99993.2109375 ) .. f .. f}
384 | {GIDX( 1.9203556776 1.11907613277 1.55043530464, 99995.421875 99995.234375
99995.421875 ) .. f .. f}
512 | {GIDX( 3.44181084633 3.4120452404 3.41762590408, 99996.3125 99996.7109375 99996.59375
) .. f .. f}
(5 rows)
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
A real case: earthquakes in the USA in 2016A real case: earthquakes in the USA in 2016
http://earthquake.usgs.gov/http://earthquake.usgs.gov/ ~100k lat/lon WGS84 points
(earthquakes in the world)
~1M SRID 102008 linestrings
(railways in the west side,
not Colorado)
http://www.openstreetmap.org/http://www.openstreetmap.org/
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
A real case: earthquakes in the USA in 2016A real case: earthquakes in the USA in 2016
http://earthquake.usgs.gov/http://earthquake.usgs.gov/ ~100k lat/lon WGS84 points
(earthquakes in the world)
~1M SRID 102008 linestrings
(railways in the west side,
not Colorado)
Which railway was closeWhich railway was close
(<10km) to an earthquake(<10km) to an earthquake
epicenter?epicenter?
http://www.openstreetmap.org/http://www.openstreetmap.org/
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
A real case: earthquakes in the USA in 2016A real case: earthquakes in the USA in 2016
=# CREATE INDEX idx_rl_gist ON westrailways USING gist
-# (ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000));
=# CREATE INDEX idx_eq_brin ON worldearthquakes USING gist (coord);
BRIN/GiST Sizes ~1/100
BRIN/GiST Times ~1/200
=# CREATE INDEX idx_rl_brin ON westrailways USING brin
-# (ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000))
-# WITH (pages_per_range=10);
=# CREATE INDEX idx_eq_brin ON worldearthquakes USING brin (coord)
-# WITH (pages_per_range=10);
BRINBRIN
GiSTGiST
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
A real case: earthquakes in the USA in 2016A real case: earthquakes in the USA in 2016
=# WITH us_eq AS (
-# SELECT coord FROM world
-# WHERE coord && ‘BOX2D(-126.90 49.73, -65.83 24.73)’::box2d
-# ) SELECT * FROM railways r, us_eq u
-# WHERE ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000) && u.coord;
• without indexes: ~60s
• with GiST: ~20ms
• with BRIN: ~400ms
...so, is GIS data “naturally” ordered?
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
It’s not a matter of “natural” order...It’s not a matter of “natural” order...
Recheck Cond: (ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000) && u.coord)
Rows Removed by Index Recheck: 10546
Heap Blocks: lossy=512
• both indexes are used: bitmapindexscan/bitmapheapscan
– indexes pages has to be read many times!
• the query plan is “complex” - more “recheck” nodes in the plan
Recheck Cond: (ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000) && u.coord)
Rows Removed by Index Recheck: 5424
Heap Blocks: lossy=42
BRINBRIN
GiSTGiST
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
...what about...what about INSERTINSERT’s?’s?
INSERT INTO railways SELECT * FROM colorado_railways;
GiST 147ms
BRIN (10) 79ms
BRIN (128) 63ms
No indexes 23ms
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
A really good testbed: LiDAR dataA really good testbed: LiDAR data
PostgreSQL extension for LiDAR data: pg_pointcloud
GiST performances:
– storage: 1TB RAID1, RAM 16GB, 8 CPU @3.3GHz,
PostgreSQL9.3
– index size ~O(table size)
– Index was used:
• up to ~300M points in bbox inclusion searches
• up to ~10M points in kNN searches
LiDAR size: ~O(109
á1011
) → less than 10% can be properly indexed!
http://www.slideshare.net/GiuseppeBroccolo/gbroccolo-foss4-geugeodbindex
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
Is the patch compatible withIs the patch compatible with pg_pointcloudpg_pointcloud??
1.6TB, ~250G points in ~560M patches1.6TB, ~250G points in ~560M patches
44thth
May, room 302C, 5:20PMMay, room 302C, 5:20PM
Here just a summary:
– BRIN/GiST ~O(10MB) not ~O(10GB)
– BRIN/GiST ~O(1h) not ~O(1day)
– bbox inclusion searches:
• GiST = 20x faster than BRIN
• BRIN = 200x faster than SeqScan
• BRIN work better with low selectivity
queries
– All BRIN index pages can be contained in RAM
– SELECTs on more than ~50% of the dataset through BRIN scan
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
ConclusionsConclusions
• BRINs can be successfully used in geo DB based on PostgreSQL
– totally support PostGIS datatype
• A patch almost ready for the next PostGIS release (2.3.0)
– easier indexes maintenance, low indexing time, low impact on concurrent
INSERTs
– less specific than GiST...but not to much!
• Really small indexes!
– GiST performances drop as well as it cannot be totally contained in RAM
– BRIN can be successfully used in LiDAR dataset, at least for bbox inclusion searches
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
Special thanks to...Special thanks to...
• Julien Rouhaud
• Ronan Dunklau
•
•
•
• Alvaro Herrera
• Emre Hesegeli
• ...and to 2ndQuadrant!
2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it
PGDay@FOSS4G.NA 2016
Raleigh, NC
3rd
May 2016
Creative Commons license
This work is licensed under a Creative Commons
Attribution-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/2.5/it/
© 2016 2ndQuadrant Italia – http://www.2ndquadrant.it

Weitere ähnliche Inhalte

Ähnlich wie BRIN indexes on geospatial databases - FOSS4G.NA 2016

Ähnlich wie BRIN indexes on geospatial databases - FOSS4G.NA 2016 (9)

gbroccolo - Use of Indexes on geospatial databases with PostgreSQL - FOSS4G.E...
gbroccolo - Use of Indexes on geospatial databases with PostgreSQL - FOSS4G.E...gbroccolo - Use of Indexes on geospatial databases with PostgreSQL - FOSS4G.E...
gbroccolo - Use of Indexes on geospatial databases with PostgreSQL - FOSS4G.E...
 
GBroccolo JRouhaud pgconfeu2016_brin4postgis
GBroccolo JRouhaud pgconfeu2016_brin4postgisGBroccolo JRouhaud pgconfeu2016_brin4postgis
GBroccolo JRouhaud pgconfeu2016_brin4postgis
 
This week in Neo4j - 28th October 2017
This week in Neo4j - 28th October 2017This week in Neo4j - 28th October 2017
This week in Neo4j - 28th October 2017
 
SuperAGILE Data Analysis System
SuperAGILE Data Analysis SystemSuperAGILE Data Analysis System
SuperAGILE Data Analysis System
 
Don't panic! - Postgres introduction
Don't panic! - Postgres introductionDon't panic! - Postgres introduction
Don't panic! - Postgres introduction
 
a look at the postgresql engine
a look at the postgresql enginea look at the postgresql engine
a look at the postgresql engine
 
Armando Benitez -- Data x Desing
Armando Benitez -- Data x DesingArmando Benitez -- Data x Desing
Armando Benitez -- Data x Desing
 
Machine Learning Applications
Machine Learning ApplicationsMachine Learning Applications
Machine Learning Applications
 
Gbroccolo pgconfeu2016 pgnfs
Gbroccolo pgconfeu2016 pgnfsGbroccolo pgconfeu2016 pgnfs
Gbroccolo pgconfeu2016 pgnfs
 

KĂźrzlich hochgeladen

➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
amitlee9823
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
SUHANI PANDEY
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Riyadh +966572737505 get cytotec
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
amitlee9823
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
gajnagarg
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
amitlee9823
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
amitlee9823
 

KĂźrzlich hochgeladen (20)

➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men  🔝malwa🔝   Escorts Ser...
➥🔝 7737669865 🔝▻ malwa Call-girls in Women Seeking Men 🔝malwa🔝 Escorts Ser...
 
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
VIP Model Call Girls Hinjewadi ( Pune ) Call ON 8005736733 Starting From 5K t...
 
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
Digital Advertising Lecture for Advanced Digital & Social Media Strategy at U...
 
Abortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get CytotecAbortion pills in Jeddah | +966572737505 | Get Cytotec
Abortion pills in Jeddah | +966572737505 | Get Cytotec
 
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get CytotecAbortion pills in Doha Qatar (+966572737505 ! Get Cytotec
Abortion pills in Doha Qatar (+966572737505 ! Get Cytotec
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
Call Girls Hsr Layout Just Call 👗 7737669865 👗 Top Class Call Girl Service Ba...
 
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Surabaya ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
Just Call Vip call girls Mysore Escorts ☎️9352988975 Two shot with one girl (...
 
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night StandCall Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Doddaballapur Road ☎ 7737669865 🥵 Book Your One night Stand
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 
Anomaly detection and data imputation within time series
Anomaly detection and data imputation within time seriesAnomaly detection and data imputation within time series
Anomaly detection and data imputation within time series
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
Thane Call Girls 7091864438 Call Girls in Thane Escort service book now -
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Rabindra Nagar  (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Rabindra Nagar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men  🔝Bangalore🔝   Esc...
➥🔝 7737669865 🔝▻ Bangalore Call-girls in Women Seeking Men 🔝Bangalore🔝 Esc...
 
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night StandCall Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Hsr Layout ☎ 7737669865 🥵 Book Your One night Stand
 
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service BangaloreCall Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
Call Girls Begur Just Call 👗 7737669865 👗 Top Class Call Girl Service Bangalore
 

BRIN indexes on geospatial databases - FOSS4G.NA 2016

  • 1. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN indexes on geospatial databases www.2ndquadrant.com
  • 2. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 ~$ whoami~$ whoami Giuseppe Broccolo, PhDGiuseppe Broccolo, PhD PostgreSQL & PostGIS consultantPostgreSQL & PostGIS consultant @giubro gbroccolo7 giuseppe.broccolo@2ndquadrant.it gbroccolo gemini__81
  • 3. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 Indexes & PostgreSQLIndexes & PostgreSQL • Binary structures on disc: – Indexing organised in nodes into 8kB pages – Speed up data access: ~O(log N) – High performance until the index can be contained in RAM • Size: ~O(N)
  • 4. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 Geospatial indexes in PostgreSQLGeospatial indexes in PostgreSQL • All datatypes can be indexed in principle... – ...just define the needed OpClass! • Operators & Support functions • Geospatial data can be larger than 8kB – A single node cannot be contained into a single page – GiST indexing allows to reduce the information that has to be indexed compressing the PostgreSQL in-core geospatial objects into its bounding box
  • 5. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 PostGIS datatypesPostGIS datatypes In PostGIS (since v0.6) geometry/geography are converted into their float-precision bounding boxes
  • 6. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 PostGIS datatypesPostGIS datatypes In PostGIS (since v0.6) geometry/geography are converted into their float-precision bounding boxes gidx/box2df are then used as storage datatype to populate the index’s nodes
  • 7. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 GIS & BigDataGIS & BigData LiDAR surveys Maps of entire countries It’s relatively easy to have to work with terabytes of geospatial data… ...can indexes be contained in RAM?
  • 8. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 A new index: Block Range INdexingA new index: Block Range INdexing – BLOCKBLOCK: set of physically adjacent 8kB pages – RANGERANGE: boundaries of data contained in the block – granularitygranularity: pages_per_range • default: blocks of 128 pages CREATE INDEX idx ON table USING brin(column) WITH (pages_per_range=10); 8kB8kB8kB8kB S. Riggs, A. Herrera
  • 9. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN - indexingBRIN - indexing 8kB8kB8kB8kB range range range range 8kB8kB8kB8kB 8kB8kB8kB8kB 8kB8kB8kB8kB c da b
  • 10. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN - indexingBRIN - indexing 8kB8kB8kB8kB range range range range 8kB8kB8kB8kB 8kB8kB8kB8kB 8kB8kB8kB8kB c da b a b c d
  • 11. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN – scan executionBRIN – scan execution 8kB8kB8kB8kB 8kB8kB8kB8kB 8kB8kB8kB8kB 8kB8kB8kB8kB c da b ...WHERE col<val1 AND col>val2; BitMapIndexScan a b c d 0 0 0 0 0 1 1
  • 12. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN – scan executionBRIN – scan execution 8kB8kB8kB8kB 8kB8kB8kB8kB 8kB8kB8kB8kB 8kB8kB8kB8kB c da b ...WHERE col<val1 AND col>val2; BitMapHeapScan a b c d 0 0 0 0 0 1 1
  • 13. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN – scan executionBRIN – scan execution 8kB8kB8kB8kB 8kB8kB8kB8kB ...WHERE col<val1 AND col>val2; “ordered” TidScan (recheck cond)
  • 14. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN – an example of execution planBRIN – an example of execution plan QUERY PLAN ------------------------------------------------------------------ -> Bitmap Heap Scan on column (cost=113.50..26741.01 rows=10000 width=20) (actual time=6.513..3094.020 rows=2499193 loops=1) Recheck Cond: column = value Rows Removed by Index Recheck: 7500807 Heap Blocks: lossy=63695 -> Bitmap Index Scan on brin_index (cost=0.00..111.00 rows=10000 width=0) (actual time=6.200..6.200 rows=637440 loops=1) Index Cond: column = value
  • 15. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN support and extensibilityBRIN support and extensibility • Two kind of support functions required in the OpClass: – minmax key values are added following sorting criteria + sorting operators – inclusion key values are added following inclusion criteria + inclusion operators – No kNN support currently available! • Extensibility – provide support functions + operators to define the OpClass http://www.postgresql.org/docs/9.5/static/brin-extensibility.html
  • 16. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN support for PostGISBRIN support for PostGIS https://github.com/dalibo/postgis/tree/for_upstream Julien RouhaudRonan Dunklau me
  • 17. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 BRIN support for PostGISBRIN support for PostGIS NO kNN SUPPORT!! – Different OpClass (inclusion support) for • 2D (default), 3D, 4D geometry • geography • box2d/box3d (cross-operators defined in the OpFamily) – Storage datatype: float-precision (such as in GiST) • gidx (3D, 4D geometry) • box2df (2D geometry, geography) – brin_inclusion_add_value() has been redefined – Operators: &&, @, ~ (2D) - &&& (3D, 4D)
  • 18. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 Now it’s time to test our patch!Now it’s time to test our patch!
  • 19. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 11stst example: “sorted”example: “sorted” geometrygeometry pointspoints ~10M, 3D, SRID=0, distribution range: 0á100kunits
  • 20. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 11stst example: “sorted”example: “sorted” geometrygeometry pointspoints ~10M, 3D, SRID=0, distribution range: 0á100kunits =# CREATE INDEX idx_gist ON points USING gist -# (geom gist_geometry_ops_nd); =# CREATE INDEX idx_brin_128 ON points USING brin -# (geom brin_geometry_inclusion_ops_3d); =# CREATE INDEX idx_brin_10 ON points USING brin -# (geom brin_geometry_inclusion_ops_3d) -# WITH (pages_per_range=10); BRIN(128)/GiST 1/2000 BRIN(10)/GiST 1/1000 BRIN(128)/GiST 1/30 BRIN(10)/GiST 1/20 Sizes Building times
  • 21. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 11stst example: “sorted”example: “sorted” geometrygeometry pointspoints ~10M, 3D, SRID=0, distribution range: 0á100kunits =# SELECT * FROM points -# WHERE ‘BOX3D(10. 10. 10., 12., 12., 12.)’::box3d &&& geom; BRIN(128)/GiST 50/1 BRIN(10)/GiST 6/1 BRIN(128)/SeqScan 1/60 BRIN(10)/SeqScan 1/350 Execution times
  • 22. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 22ndnd example: “unsorted”example: “unsorted” geometrygeometry pointspoints ~10M, 3D, SRID=0, distribution range: 0á100kunits =# CREATE TABLE unsorted_points AS -# SELECT * FROM points ORDER BY random(); =# SELECT * FROM unsorted_points -# WHERE ‘BOX3D(10. 10. 10., 12., 12., 12.)’::box3d &&& geom; BRIN(128)/GiST 2800/1 BRIN(10)/GiST 400/1 BRIN(128)/SeqScan 1/1 BRIN(10)/SeqScan 1/12 Execution times
  • 23. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 22ndnd example: “unsorted”example: “unsorted” geometrygeometry pointspoints =# CREATE EXTENSION pageinspect; =# SELECT blknum, value FROM brin_page_items(get_raw_page('idx_brin_128', 2), 'idx_brin_128') -# LIMIT 5; blknum | value --------+------------------------------------------------------------------------ 0 | {GIDX( 1.11394846439 1.64980053902 1.11335003376, 99982.2578125 99982.640625 99982.1171875 ) .. f .. f} 128 | {GIDX( 0.224781364202 0.184096381068 0.798862099648, 99995.859375 99995.171875 99995.0390625 ) .. f .. f} 256 | {GIDX( 6.25802087784 6.50119876862 6.8031873703, 99993.15625 99993.8203125 99993.2109375 ) .. f .. f} 384 | {GIDX( 1.9203556776 1.11907613277 1.55043530464, 99995.421875 99995.234375 99995.421875 ) .. f .. f} 512 | {GIDX( 3.44181084633 3.4120452404 3.41762590408, 99996.3125 99996.7109375 99996.59375 ) .. f .. f} (5 rows)
  • 24. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 A real case: earthquakes in the USA in 2016A real case: earthquakes in the USA in 2016 http://earthquake.usgs.gov/http://earthquake.usgs.gov/ ~100k lat/lon WGS84 points (earthquakes in the world) ~1M SRID 102008 linestrings (railways in the west side, not Colorado) http://www.openstreetmap.org/http://www.openstreetmap.org/
  • 25. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 A real case: earthquakes in the USA in 2016A real case: earthquakes in the USA in 2016 http://earthquake.usgs.gov/http://earthquake.usgs.gov/ ~100k lat/lon WGS84 points (earthquakes in the world) ~1M SRID 102008 linestrings (railways in the west side, not Colorado) Which railway was closeWhich railway was close (<10km) to an earthquake(<10km) to an earthquake epicenter?epicenter? http://www.openstreetmap.org/http://www.openstreetmap.org/
  • 26. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 A real case: earthquakes in the USA in 2016A real case: earthquakes in the USA in 2016 =# CREATE INDEX idx_rl_gist ON westrailways USING gist -# (ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000)); =# CREATE INDEX idx_eq_brin ON worldearthquakes USING gist (coord); BRIN/GiST Sizes ~1/100 BRIN/GiST Times ~1/200 =# CREATE INDEX idx_rl_brin ON westrailways USING brin -# (ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000)) -# WITH (pages_per_range=10); =# CREATE INDEX idx_eq_brin ON worldearthquakes USING brin (coord) -# WITH (pages_per_range=10); BRINBRIN GiSTGiST
  • 27. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 A real case: earthquakes in the USA in 2016A real case: earthquakes in the USA in 2016 =# WITH us_eq AS ( -# SELECT coord FROM world -# WHERE coord && ‘BOX2D(-126.90 49.73, -65.83 24.73)’::box2d -# ) SELECT * FROM railways r, us_eq u -# WHERE ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000) && u.coord; • without indexes: ~60s • with GiST: ~20ms • with BRIN: ~400ms ...so, is GIS data “naturally” ordered?
  • 28. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 It’s not a matter of “natural” order...It’s not a matter of “natural” order... Recheck Cond: (ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000) && u.coord) Rows Removed by Index Recheck: 10546 Heap Blocks: lossy=512 • both indexes are used: bitmapindexscan/bitmapheapscan – indexes pages has to be read many times! • the query plan is “complex” - more “recheck” nodes in the plan Recheck Cond: (ST_Buffer(GEOGRAPHY(ST_Trasform(geom), 4326), 10000) && u.coord) Rows Removed by Index Recheck: 5424 Heap Blocks: lossy=42 BRINBRIN GiSTGiST
  • 29. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 ...what about...what about INSERTINSERT’s?’s? INSERT INTO railways SELECT * FROM colorado_railways; GiST 147ms BRIN (10) 79ms BRIN (128) 63ms No indexes 23ms
  • 30. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 A really good testbed: LiDAR dataA really good testbed: LiDAR data PostgreSQL extension for LiDAR data: pg_pointcloud GiST performances: – storage: 1TB RAID1, RAM 16GB, 8 CPU @3.3GHz, PostgreSQL9.3 – index size ~O(table size) – Index was used: • up to ~300M points in bbox inclusion searches • up to ~10M points in kNN searches LiDAR size: ~O(109 á1011 ) → less than 10% can be properly indexed! http://www.slideshare.net/GiuseppeBroccolo/gbroccolo-foss4-geugeodbindex
  • 31. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 Is the patch compatible withIs the patch compatible with pg_pointcloudpg_pointcloud?? 1.6TB, ~250G points in ~560M patches1.6TB, ~250G points in ~560M patches 44thth May, room 302C, 5:20PMMay, room 302C, 5:20PM Here just a summary: – BRIN/GiST ~O(10MB) not ~O(10GB) – BRIN/GiST ~O(1h) not ~O(1day) – bbox inclusion searches: • GiST = 20x faster than BRIN • BRIN = 200x faster than SeqScan • BRIN work better with low selectivity queries – All BRIN index pages can be contained in RAM – SELECTs on more than ~50% of the dataset through BRIN scan
  • 32. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 ConclusionsConclusions • BRINs can be successfully used in geo DB based on PostgreSQL – totally support PostGIS datatype • A patch almost ready for the next PostGIS release (2.3.0) – easier indexes maintenance, low indexing time, low impact on concurrent INSERTs – less specific than GiST...but not to much! • Really small indexes! – GiST performances drop as well as it cannot be totally contained in RAM – BRIN can be successfully used in LiDAR dataset, at least for bbox inclusion searches
  • 33. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 Special thanks to...Special thanks to... • Julien Rouhaud • Ronan Dunklau • • • • Alvaro Herrera • Emre Hesegeli • ...and to 2ndQuadrant!
  • 34. 2ndQuadrant Italia Giuseppe Broccolo – giuseppe.broccolo@2ndquadrant.it PGDay@FOSS4G.NA 2016 Raleigh, NC 3rd May 2016 Creative Commons license This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License http://creativecommons.org/licenses/by-nc-sa/2.5/it/ Š 2016 2ndQuadrant Italia – http://www.2ndquadrant.it