SlideShare a Scribd company logo
(Ab)using 4D indexing in
PostGIS 2.2 with
PostgreSQL 9.5 to give you
the perfect match
Victor Blomqvist
vb@viblo.se
blomqvist@tantanapp.com
Tantan (探探)
March 19, pgDay Asia 2016 in Singapore
1tantanapp.com
At Tantan we use PostgreSQL &
PostGIS for everything!
2tantanapp.com
Suggesting users is difficult
• How should we rank them?
• How can it execute quickly?
(At Tantan we need to do 1000 ranking queries per
second at peak!)
tantanapp.com 3
The exciting new feature in
PostGIS is this:
<<->>
tantanapp.com 4
Today I will show how to take
advantage of the 4th dimension!
1. Use double the amount of dimensions from 2
2. …
3. Profit!
tantanapp.com 5
We will look at 3 different properties
to help our suggestion SELECT
1. Popularity
2. Age
3. Activity
tantanapp.com 6
Let’s begin with 2 dimensions
tantanapp.com 7
Y
(Latitude)
X
(Longitude)
Table and index
CREATE TABLE users (
id serial PRIMARY KEY,
birthdate date,
location geometry,
active_time timestamp,
popularity double precision
);
CREATE INDEX users_location_gix
ON users USING GIST (location);
tantanapp.com 8
Selecting
SELECT * FROM users
ORDER BY location <-> ST_MakePoint(103.8, 1.3)
/* Singapore */
LIMIT 10;
tantanapp.com 9
Lets look at our first case
1. Popularity <--
2. Age
3. Activity
tantanapp.com 10
The popularity formula
Popularity = likes / (likes + dislikes)
tantanapp.com 11
Order by location and popularity
WITH x AS (SELECT * FROM users
ORDER BY location <-> ST_MakePoint(103.8, 1.3)
LIMIT 100)
SELECT * FROM x
ORDER BY
ST_Distance(location::geography, ST_MakePoint(103.8, 1.3))
* 1 / (popularity+1)
LIMIT 10;
tantanapp.com 12
Picture of x-y-z axis
tantanapp.com 13
X
(Longitude)
Y
(Latitude)
Z
(Popularity)
Adding a 3rd dimension!
ALTER TABLE users ADD COLUMN loc_pop geometry;
UPDATE users
SET loc_pop = ST_makepoint(ST_X(location),
ST_Y(location), 0.01 * 1 / (popularity+1));
CREATE INDEX users_loc_pop_gix
ON users USING GIST (loc_pop gist_geometry_ops_nd);
tantanapp.com 14
To use our new 3D index we need
to use the new <<->> operator
<<->> — Returns the n-D distance between the centroids
of A and B bounding boxes.
This operand will make use of n-D GiST indexes that may
be available on the geometries. It is different from other
operators that use spatial indexes in that the spatial
index is only used when the operator is in the ORDER BY
clause.
* http://postgis.net/docs/manual-2.2/geometry_distance_centroid_nd.html
tantanapp.com 15
With <<->> our query becomes
SELECT * FROM users
ORDER BY loc_pop <<->> ST_MakePoint(103.8, 1.3, 0)
LIMIT 10;
tantanapp.com 16
Second case
1. Popularity
2. Age <--
3. Activity
tantanapp.com 17
A quick review of our table:
CREATE TABLE users (
id serial PRIMARY KEY,
birthdate date,
location geometry,
active_time timestamp,
popularity double precision
);
tantanapp.com 18
Selecting with age filter
SELECT * FROM users
WHERE age(birthdate) between '20 years' AND '30 years'
ORDER BY location <-> ST_MakePoint(103.8, 1.3)
LIMIT 10;
tantanapp.com 19
A very selective user might only
want to look at 74 year olds
SELECT * FROM users
WHERE age(birthdate) between '74 years' AND '75 years'
ORDER BY location <-> ST_MakePoint(103.8, 1.3)
LIMIT 10;
tantanapp.com 20
Explain analyze of the query
Limit (cost=0.41..62011.93 rows=10 width=96) (actual
time=49.456..551.955 rows=10 loops=1)
-> Index Scan using users_location_gix on users
(cost=0.41..1103805.51 rows=178 width=96) (actual time=49.398..546.631
rows=10 loops=1)
Order By: (location <-> 'XXX'::geometry)
Filter: ((birthdate >= (now() - '75 years'::interval)) AND (birthdate <=
(now() - '74 years'::interval)))
Rows Removed by Filter: 192609
Planning time: 0.157 ms
Execution time: 553.151 ms
tantanapp.com 21
This is a real
problem
tantanapp.com 22
Possible solutions?
• Prevent searches of
restricted ages
• Add a distance
restriction
• Add age to the geo index
tantanapp.com 23
Adding age to the geo index
ALTER TABLE users ADD COLUMN loc_age geometry;
UPDATE users
SET loc_age = ST_makepoint(ST_X(location), ST_Y(location),
Extract('year' FROM birthdate)/100000);
CREATE INDEX users_loc_age_gix ON users USING GIST (loc_age
gist_geometry_ops_nd);
tantanapp.com 24
Updated query
SELECT * FROM users
WHERE loc_age &&&
ST_MakeLine(
ST_MakePoint(180, 90, Extract('year' FROM Now() - interval '74
years')/100000),
ST_MakePoint(-180, -90, Extract('year' FROM Now() - interval '75
years')/100000))
ORDER BY loc_age <<->> ST_MakePoint(103.8, 1.3, 0)
LIMIT 10;
tantanapp.com 25
Looking at the execution plan we
can see that all is good
Limit (cost=0.41..8.43 rows=1 width=136) (actual time=15.294..16.082
rows=10 loops=1)
-> Index Scan using users_loc_age_gix on users (cost=0.41..8.43 rows=1
width=136) (actual time=14.685..14.948 rows=10 loops=1)
Index Cond: (loc_age &&& 'XXX'::geometry)
Order By: (loc_age <<->> 'XXX'::geometry)
Planning time: 0.332 ms
Execution time: 19.053 ms
tantanapp.com 26
Looking at the result we see that
something is wrong
UserID Age
6827677 74 years 11 mons 7 days
1281456 75 years 15 days
1269119 73 years 7 mons 27 days
5791734 73 years 7 mons 8 days
3875002 74 years 7 mons 14 days
6373179 73 years 5 mons 8 days
3727434 74 years 7 mons 21 days
5214330 74 years 10 days
3127049 74 years 8 mons 22 days
6390900 74 years 21 days
tantanapp.com 27
Solution: Keep the non-geometry
where statement
SELECT * FROM users
WHERE age(birthdate) BETWEEN '74 years' AND '75 years'
AND loc_age &&&
ST_MakeLine(
ST_MakePoint(180, 90, Extract('year' FROM Now() - interval '74
years')/100000),
ST_MakePoint(-180, -90, Extract('year' FROM Now() - interval '75
years')/100000))
ORDER BY loc_age <<->> ST_MakePoint(103.8, 1.3, 0)
LIMIT 10;
tantanapp.com 28
Finally we look at Activity
1. Popularity
2. Age
3. Activity <--
tantanapp.com 29
Order by last active time
WITH x AS (SELECT * FROM users
ORDER BY location <-> ST_MakePoint(103.8, 1.3)
LIMIT 100)
SELECT * FROM x
ORDER BY
ST_Distance(location::geography, ST_MakePoint(103.8, 1.3))
* Extract(Now() - active_time)
LIMIT 10;
tantanapp.com 30
What is the difference between
time, popularity and age?
• Popularity is bounded, a users popularity can range
between 0 and 1.
• Age is also bounded, and static. All our users are
between 16 and 100 years old and their birthdate
never change.
• Time increase infinitely in one direction.
tantanapp.com 31
Adding time to the geo column
ALTER TABLE users ADD COLUMN loc_active geometry;
UPDATE users
SET loc_active = ST_MakePoint(ST_X(location), ST_Y(location),
Extract('epoch' FROM active_time) / 60 / 10000);
CREATE INDEX users_loc_active_gix
ON users USING GIST (loc_active gist_geometry_ops_nd);
tantanapp.com 32
Select with time becomes
SELECT * FROM users
ORDER BY loc_active <<->> ST_MakePoint(103.8, 1.3,
Extract('epoch' FROM Now()) / 60 / 10000)
LIMIT 10;
tantanapp.com 33
What we talked about so far
1. Location X and Y
2. Popularity
3. Age
4. Activity
tantanapp.com 34
Adding a 4th dimension
ALTER TABLE users ADD COLUMN loc_pop_age geometry;
UPDATE users
SET loc_pop_age =
ST_MakePoint(ST_X(location), ST_Y(location),
0.01 * 1 / (popularity+1),
Extract('year' FROM birthdate)/100000);
CREATE INDEX users_loc_pop_age_gix
ON users USING GIST (loc_pop_age gist_geometry_ops_nd);
tantanapp.com 35
Adding a 4th dimension - Query
SELECT * FROM users
WHERE loc_pop_age &&&
ST_MakeLine(
ST_MakePoint(180, 90, -100, Extract('year' FROM Now() - interval
'20 years')/100000),
ST_MakePoint(-180, -90, 100, Extract('year' FROM Now() - interval
'30 years')/100000))
ORDER BY loc_pop_age <<->> ST_MakePoint(103.8, 1.3, 0, 0)
LIMIT 10;
tantanapp.com 36
Query runtimes 2D vs 3D vs 4D
tantanapp.com 37
0 10 20 30 40 50
Location
Location + popularity
Location + age (20-30)
Location + age (74)
Location + activity
Location + pop + age (4D)
3D/4D index (ms) 2D index (ms)
Query times did not impress.
What about index sizes?
tantanapp.com 38
0 50 100 150 200
users_pkey
users_location_gix
users_loc_pop_gix
users_loc_pop_age_gix
users_loc_age_gix
users_loc_active_gix
Size bloated (MB) Size fresh(MB)
Conclusion
1. Popularity
• Pro: Improves ranking?
• Con: Makes it more difficult to reason about the ranking formula
• Con: Makes the query slower
2. Age
• Pro: Fixes query time of outlier queries
• Con: Make the average query time longer
• Con: Have to take special care to not disturb the normal ranking
3. Time
• Pro: Improves ranking?
• Con: Much more difficult to reason about the ranking formula
• Con: Makes the query slower
tantanapp.com 39
Conclusion
Its more difficult to use the 3rd and 4th dimension
than what a quick glance reveals. Test extensively!
tantanapp.com 40
tantanapp.com 41
Questions?
tantanapp.com 42
Thank You!
blomqvist@tantanapp.com
vb@viblo.se
Ad

More Related Content

Viewers also liked (20)

Lightening Talk - PostgreSQL Worst Practices
Lightening Talk - PostgreSQL Worst PracticesLightening Talk - PostgreSQL Worst Practices
Lightening Talk - PostgreSQL Worst Practices
PGConf APAC
 
Query Parallelism in PostgreSQL: What's coming next?
Query Parallelism in PostgreSQL: What's coming next?Query Parallelism in PostgreSQL: What's coming next?
Query Parallelism in PostgreSQL: What's coming next?
PGConf APAC
 
Lessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tLessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’t
PGConf APAC
 
Use Case: PostGIS and Agribotics
Use Case: PostGIS and AgriboticsUse Case: PostGIS and Agribotics
Use Case: PostGIS and Agribotics
PGConf APAC
 
How to teach an elephant to rock'n'roll
How to teach an elephant to rock'n'rollHow to teach an elephant to rock'n'roll
How to teach an elephant to rock'n'roll
PGConf APAC
 
PostgreSQL Rocks Indonesia
PostgreSQL Rocks IndonesiaPostgreSQL Rocks Indonesia
PostgreSQL Rocks Indonesia
PGConf APAC
 
There is Javascript in my SQL
There is Javascript in my SQLThere is Javascript in my SQL
There is Javascript in my SQL
PGConf APAC
 
Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!
PGConf APAC
 
Introduction to Vacuum Freezing and XID
Introduction to Vacuum Freezing and XIDIntroduction to Vacuum Freezing and XID
Introduction to Vacuum Freezing and XID
PGConf APAC
 
PostgreSQL Enterprise Class Features and Capabilities
PostgreSQL Enterprise Class Features and CapabilitiesPostgreSQL Enterprise Class Features and Capabilities
PostgreSQL Enterprise Class Features and Capabilities
PGConf APAC
 
Security Best Practices for your Postgres Deployment
Security Best Practices for your Postgres DeploymentSecurity Best Practices for your Postgres Deployment
Security Best Practices for your Postgres Deployment
PGConf APAC
 
What's New in PostgreSQL 9.6
What's New in PostgreSQL 9.6What's New in PostgreSQL 9.6
What's New in PostgreSQL 9.6
EDB
 
Useful PostgreSQL Extensions
Useful PostgreSQL ExtensionsUseful PostgreSQL Extensions
Useful PostgreSQL Extensions
EDB
 
Best Practices for Becoming an Exceptional Postgres DBA
Best Practices for Becoming an Exceptional Postgres DBA Best Practices for Becoming an Exceptional Postgres DBA
Best Practices for Becoming an Exceptional Postgres DBA
EDB
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
Federico Campoli
 
What's New in PostgreSQL 9.3
What's New in PostgreSQL 9.3What's New in PostgreSQL 9.3
What's New in PostgreSQL 9.3
EDB
 
EnterpriseDB BackUp and Recovery Tool
EnterpriseDB BackUp and Recovery ToolEnterpriseDB BackUp and Recovery Tool
EnterpriseDB BackUp and Recovery Tool
EDB
 
PostgreSQL DBA Neler Yapar?
PostgreSQL DBA Neler Yapar?PostgreSQL DBA Neler Yapar?
PostgreSQL DBA Neler Yapar?
Gulcin Yildirim Jelinek
 
TTÜ Geeky Weekly
TTÜ Geeky WeeklyTTÜ Geeky Weekly
TTÜ Geeky Weekly
Gulcin Yildirim Jelinek
 
Founding a LLC in Turkey
Founding a LLC in TurkeyFounding a LLC in Turkey
Founding a LLC in Turkey
Gulcin Yildirim Jelinek
 
Lightening Talk - PostgreSQL Worst Practices
Lightening Talk - PostgreSQL Worst PracticesLightening Talk - PostgreSQL Worst Practices
Lightening Talk - PostgreSQL Worst Practices
PGConf APAC
 
Query Parallelism in PostgreSQL: What's coming next?
Query Parallelism in PostgreSQL: What's coming next?Query Parallelism in PostgreSQL: What's coming next?
Query Parallelism in PostgreSQL: What's coming next?
PGConf APAC
 
Lessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’tLessons PostgreSQL learned from commercial databases, and didn’t
Lessons PostgreSQL learned from commercial databases, and didn’t
PGConf APAC
 
Use Case: PostGIS and Agribotics
Use Case: PostGIS and AgriboticsUse Case: PostGIS and Agribotics
Use Case: PostGIS and Agribotics
PGConf APAC
 
How to teach an elephant to rock'n'roll
How to teach an elephant to rock'n'rollHow to teach an elephant to rock'n'roll
How to teach an elephant to rock'n'roll
PGConf APAC
 
PostgreSQL Rocks Indonesia
PostgreSQL Rocks IndonesiaPostgreSQL Rocks Indonesia
PostgreSQL Rocks Indonesia
PGConf APAC
 
There is Javascript in my SQL
There is Javascript in my SQLThere is Javascript in my SQL
There is Javascript in my SQL
PGConf APAC
 
Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!Why we love pgpool-II and why we hate it!
Why we love pgpool-II and why we hate it!
PGConf APAC
 
Introduction to Vacuum Freezing and XID
Introduction to Vacuum Freezing and XIDIntroduction to Vacuum Freezing and XID
Introduction to Vacuum Freezing and XID
PGConf APAC
 
PostgreSQL Enterprise Class Features and Capabilities
PostgreSQL Enterprise Class Features and CapabilitiesPostgreSQL Enterprise Class Features and Capabilities
PostgreSQL Enterprise Class Features and Capabilities
PGConf APAC
 
Security Best Practices for your Postgres Deployment
Security Best Practices for your Postgres DeploymentSecurity Best Practices for your Postgres Deployment
Security Best Practices for your Postgres Deployment
PGConf APAC
 
What's New in PostgreSQL 9.6
What's New in PostgreSQL 9.6What's New in PostgreSQL 9.6
What's New in PostgreSQL 9.6
EDB
 
Useful PostgreSQL Extensions
Useful PostgreSQL ExtensionsUseful PostgreSQL Extensions
Useful PostgreSQL Extensions
EDB
 
Best Practices for Becoming an Exceptional Postgres DBA
Best Practices for Becoming an Exceptional Postgres DBA Best Practices for Becoming an Exceptional Postgres DBA
Best Practices for Becoming an Exceptional Postgres DBA
EDB
 
Postgresql database administration volume 1
Postgresql database administration volume 1Postgresql database administration volume 1
Postgresql database administration volume 1
Federico Campoli
 
What's New in PostgreSQL 9.3
What's New in PostgreSQL 9.3What's New in PostgreSQL 9.3
What's New in PostgreSQL 9.3
EDB
 
EnterpriseDB BackUp and Recovery Tool
EnterpriseDB BackUp and Recovery ToolEnterpriseDB BackUp and Recovery Tool
EnterpriseDB BackUp and Recovery Tool
EDB
 

Similar to (Ab)using 4d Indexing (20)

Geospatial Data Analysis and Visualization in Python
Geospatial Data Analysis and Visualization in PythonGeospatial Data Analysis and Visualization in Python
Geospatial Data Analysis and Visualization in Python
Halfdan Rump
 
From the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepFrom the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by Step
Igalia
 
12 things Oracle DBAs must know about SQL
12 things Oracle DBAs must know about SQL12 things Oracle DBAs must know about SQL
12 things Oracle DBAs must know about SQL
SolarWinds
 
Geopy module in python
Geopy module in pythonGeopy module in python
Geopy module in python
Ashmita Dhakal
 
Tictac
TictacTictac
Tictac
Upendra Sengar
 
Opensource gis development - part 2
Opensource gis development - part 2Opensource gis development - part 2
Opensource gis development - part 2
Andrea Antonello
 
DeepScan: Exploiting Deep Learning for Malicious Account Detection in Locatio...
DeepScan: Exploiting Deep Learning for Malicious Account Detection in Locatio...DeepScan: Exploiting Deep Learning for Malicious Account Detection in Locatio...
DeepScan: Exploiting Deep Learning for Malicious Account Detection in Locatio...
yeung2000
 
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Citus Data
 
10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting Spatial
FAO
 
R getting spatial
R getting spatialR getting spatial
R getting spatial
FAO
 
The Future of Sharding
The Future of ShardingThe Future of Sharding
The Future of Sharding
EDB
 
Tic tac toe game code
Tic tac toe game codeTic tac toe game code
Tic tac toe game code
Upendra Sengar
 
Tic tac toe
Tic tac toeTic tac toe
Tic tac toe
Upendra Sengar
 
10. R getting spatial
10.  R getting spatial10.  R getting spatial
10. R getting spatial
ExternalEvents
 
Nyc open data project ii -- predict where to get and return my citibike
Nyc open data project ii -- predict where to get and return my citibikeNyc open data project ii -- predict where to get and return my citibike
Nyc open data project ii -- predict where to get and return my citibike
Vivian S. Zhang
 
From the proposal to ECMAScript, step by step
From the proposal to ECMAScript, step by stepFrom the proposal to ECMAScript, step by step
From the proposal to ECMAScript, step by step
Igalia
 
Just in time (series) - KairosDB
Just in time (series) - KairosDBJust in time (series) - KairosDB
Just in time (series) - KairosDB
Victor Anjos
 
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEXWhere the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Jim Czuprynski
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
Connor McDonald
 
GeoMesa on Apache Spark SQL with Anthony Fox
GeoMesa on Apache Spark SQL with Anthony FoxGeoMesa on Apache Spark SQL with Anthony Fox
GeoMesa on Apache Spark SQL with Anthony Fox
Databricks
 
Geospatial Data Analysis and Visualization in Python
Geospatial Data Analysis and Visualization in PythonGeospatial Data Analysis and Visualization in Python
Geospatial Data Analysis and Visualization in Python
Halfdan Rump
 
From the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by StepFrom the proposal to ECMAScript – Step by Step
From the proposal to ECMAScript – Step by Step
Igalia
 
12 things Oracle DBAs must know about SQL
12 things Oracle DBAs must know about SQL12 things Oracle DBAs must know about SQL
12 things Oracle DBAs must know about SQL
SolarWinds
 
Geopy module in python
Geopy module in pythonGeopy module in python
Geopy module in python
Ashmita Dhakal
 
Opensource gis development - part 2
Opensource gis development - part 2Opensource gis development - part 2
Opensource gis development - part 2
Andrea Antonello
 
DeepScan: Exploiting Deep Learning for Malicious Account Detection in Locatio...
DeepScan: Exploiting Deep Learning for Malicious Account Detection in Locatio...DeepScan: Exploiting Deep Learning for Malicious Account Detection in Locatio...
DeepScan: Exploiting Deep Learning for Malicious Account Detection in Locatio...
yeung2000
 
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Around the world with extensions | PostgreSQL Conference Europe 2018 | Craig ...
Citus Data
 
10. Getting Spatial
10. Getting Spatial10. Getting Spatial
10. Getting Spatial
FAO
 
R getting spatial
R getting spatialR getting spatial
R getting spatial
FAO
 
The Future of Sharding
The Future of ShardingThe Future of Sharding
The Future of Sharding
EDB
 
Nyc open data project ii -- predict where to get and return my citibike
Nyc open data project ii -- predict where to get and return my citibikeNyc open data project ii -- predict where to get and return my citibike
Nyc open data project ii -- predict where to get and return my citibike
Vivian S. Zhang
 
From the proposal to ECMAScript, step by step
From the proposal to ECMAScript, step by stepFrom the proposal to ECMAScript, step by step
From the proposal to ECMAScript, step by step
Igalia
 
Just in time (series) - KairosDB
Just in time (series) - KairosDBJust in time (series) - KairosDB
Just in time (series) - KairosDB
Victor Anjos
 
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEXWhere the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Jim Czuprynski
 
UKOUG 2019 - SQL features
UKOUG 2019 - SQL featuresUKOUG 2019 - SQL features
UKOUG 2019 - SQL features
Connor McDonald
 
GeoMesa on Apache Spark SQL with Anthony Fox
GeoMesa on Apache Spark SQL with Anthony FoxGeoMesa on Apache Spark SQL with Anthony Fox
GeoMesa on Apache Spark SQL with Anthony Fox
Databricks
 
Ad

More from PGConf APAC (17)

PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC
 
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC 2018: PostgreSQL 10 - Replication goes LogicalPGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQLPGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQLPGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC
 
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC
 
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companionPGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC
 
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC 2018 - High performance json  postgre-sql vs. mongodbPGConf APAC 2018 - High performance json  postgre-sql vs. mongodb
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC
 
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC 2018 - Monitoring PostgreSQL at ScalePGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC
 
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQLPGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC 2018 - PostgreSQL performance comparison in various cloudsPGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC
 
PGConf APAC 2018 - Tale from Trenches
PGConf APAC 2018 - Tale from TrenchesPGConf APAC 2018 - Tale from Trenches
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC 2018 Keynote: PostgreSQL goes elevenPGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC
 
Amazon (AWS) Aurora
Amazon (AWS) AuroraAmazon (AWS) Aurora
Amazon (AWS) Aurora
PGConf APAC
 
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC 2018: Sponsored Talk by Fujitsu - The growing mandatory requireme...
PGConf APAC
 
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC 2018: PostgreSQL 10 - Replication goes LogicalPGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC 2018: PostgreSQL 10 - Replication goes Logical
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQLPGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC 2018 - Lightening Talk #3: How To Contribute to PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQLPGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC 2018 - Lightening Talk #2 - Centralizing Authorization in PostgreSQL
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
Sponsored Talk @ PGConf APAC 2018 - Choosing the right partner in your Postgr...
PGConf APAC
 
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC 2018 - A PostgreSQL DBAs Toolbelt for 2018
PGConf APAC
 
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companionPGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC 2018 - Patroni: Kubernetes-native PostgreSQL companion
PGConf APAC
 
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC 2018 - High performance json  postgre-sql vs. mongodbPGConf APAC 2018 - High performance json  postgre-sql vs. mongodb
PGConf APAC 2018 - High performance json postgre-sql vs. mongodb
PGConf APAC
 
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC 2018 - Monitoring PostgreSQL at ScalePGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC 2018 - Monitoring PostgreSQL at Scale
PGConf APAC
 
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQLPGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC 2018 - Where's Waldo - Text Search and Pattern in PostgreSQL
PGConf APAC
 
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC 2018 - Managing replication clusters with repmgr, Barman and PgBo...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC 2018 - PostgreSQL HA with Pgpool-II and whats been happening in P...
PGConf APAC
 
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC 2018 - PostgreSQL performance comparison in various cloudsPGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC 2018 - PostgreSQL performance comparison in various clouds
PGConf APAC
 
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
Sponsored Talk @ PGConf APAC 2018 - Migrating Oracle to EDB Postgres Approach...
PGConf APAC
 
PGConf APAC 2018 - Tale from Trenches
PGConf APAC 2018 - Tale from TrenchesPGConf APAC 2018 - Tale from Trenches
PGConf APAC 2018 - Tale from Trenches
PGConf APAC
 
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC 2018 Keynote: PostgreSQL goes elevenPGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC 2018 Keynote: PostgreSQL goes eleven
PGConf APAC
 
Amazon (AWS) Aurora
Amazon (AWS) AuroraAmazon (AWS) Aurora
Amazon (AWS) Aurora
PGConf APAC
 
Ad

Recently uploaded (20)

Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdfSAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
SAP Modernization: Maximizing the Value of Your SAP S/4HANA Migration.pdf
Precisely
 
HCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser EnvironmentsHCL Nomad Web – Best Practices and Managing Multiuser Environments
HCL Nomad Web – Best Practices and Managing Multiuser Environments
panagenda
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Enhancing ICU Intelligence: How Our Functional Testing Enabled a Healthcare I...
Impelsys Inc.
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Quantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur MorganQuantum Computing Quick Research Guide by Arthur Morgan
Quantum Computing Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
#StandardsGoals for 2025: Standards & certification roundup - Tech Forum 2025
BookNet Canada
 
What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...What is Model Context Protocol(MCP) - The new technology for communication bw...
What is Model Context Protocol(MCP) - The new technology for communication bw...
Vishnu Singh Chundawat
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 

(Ab)using 4d Indexing

  • 1. (Ab)using 4D indexing in PostGIS 2.2 with PostgreSQL 9.5 to give you the perfect match Victor Blomqvist [email protected] [email protected] Tantan (探探) March 19, pgDay Asia 2016 in Singapore 1tantanapp.com
  • 2. At Tantan we use PostgreSQL & PostGIS for everything! 2tantanapp.com
  • 3. Suggesting users is difficult • How should we rank them? • How can it execute quickly? (At Tantan we need to do 1000 ranking queries per second at peak!) tantanapp.com 3
  • 4. The exciting new feature in PostGIS is this: <<->> tantanapp.com 4
  • 5. Today I will show how to take advantage of the 4th dimension! 1. Use double the amount of dimensions from 2 2. … 3. Profit! tantanapp.com 5
  • 6. We will look at 3 different properties to help our suggestion SELECT 1. Popularity 2. Age 3. Activity tantanapp.com 6
  • 7. Let’s begin with 2 dimensions tantanapp.com 7 Y (Latitude) X (Longitude)
  • 8. Table and index CREATE TABLE users ( id serial PRIMARY KEY, birthdate date, location geometry, active_time timestamp, popularity double precision ); CREATE INDEX users_location_gix ON users USING GIST (location); tantanapp.com 8
  • 9. Selecting SELECT * FROM users ORDER BY location <-> ST_MakePoint(103.8, 1.3) /* Singapore */ LIMIT 10; tantanapp.com 9
  • 10. Lets look at our first case 1. Popularity <-- 2. Age 3. Activity tantanapp.com 10
  • 11. The popularity formula Popularity = likes / (likes + dislikes) tantanapp.com 11
  • 12. Order by location and popularity WITH x AS (SELECT * FROM users ORDER BY location <-> ST_MakePoint(103.8, 1.3) LIMIT 100) SELECT * FROM x ORDER BY ST_Distance(location::geography, ST_MakePoint(103.8, 1.3)) * 1 / (popularity+1) LIMIT 10; tantanapp.com 12
  • 13. Picture of x-y-z axis tantanapp.com 13 X (Longitude) Y (Latitude) Z (Popularity)
  • 14. Adding a 3rd dimension! ALTER TABLE users ADD COLUMN loc_pop geometry; UPDATE users SET loc_pop = ST_makepoint(ST_X(location), ST_Y(location), 0.01 * 1 / (popularity+1)); CREATE INDEX users_loc_pop_gix ON users USING GIST (loc_pop gist_geometry_ops_nd); tantanapp.com 14
  • 15. To use our new 3D index we need to use the new <<->> operator <<->> — Returns the n-D distance between the centroids of A and B bounding boxes. This operand will make use of n-D GiST indexes that may be available on the geometries. It is different from other operators that use spatial indexes in that the spatial index is only used when the operator is in the ORDER BY clause. * http://postgis.net/docs/manual-2.2/geometry_distance_centroid_nd.html tantanapp.com 15
  • 16. With <<->> our query becomes SELECT * FROM users ORDER BY loc_pop <<->> ST_MakePoint(103.8, 1.3, 0) LIMIT 10; tantanapp.com 16
  • 17. Second case 1. Popularity 2. Age <-- 3. Activity tantanapp.com 17
  • 18. A quick review of our table: CREATE TABLE users ( id serial PRIMARY KEY, birthdate date, location geometry, active_time timestamp, popularity double precision ); tantanapp.com 18
  • 19. Selecting with age filter SELECT * FROM users WHERE age(birthdate) between '20 years' AND '30 years' ORDER BY location <-> ST_MakePoint(103.8, 1.3) LIMIT 10; tantanapp.com 19
  • 20. A very selective user might only want to look at 74 year olds SELECT * FROM users WHERE age(birthdate) between '74 years' AND '75 years' ORDER BY location <-> ST_MakePoint(103.8, 1.3) LIMIT 10; tantanapp.com 20
  • 21. Explain analyze of the query Limit (cost=0.41..62011.93 rows=10 width=96) (actual time=49.456..551.955 rows=10 loops=1) -> Index Scan using users_location_gix on users (cost=0.41..1103805.51 rows=178 width=96) (actual time=49.398..546.631 rows=10 loops=1) Order By: (location <-> 'XXX'::geometry) Filter: ((birthdate >= (now() - '75 years'::interval)) AND (birthdate <= (now() - '74 years'::interval))) Rows Removed by Filter: 192609 Planning time: 0.157 ms Execution time: 553.151 ms tantanapp.com 21
  • 22. This is a real problem tantanapp.com 22
  • 23. Possible solutions? • Prevent searches of restricted ages • Add a distance restriction • Add age to the geo index tantanapp.com 23
  • 24. Adding age to the geo index ALTER TABLE users ADD COLUMN loc_age geometry; UPDATE users SET loc_age = ST_makepoint(ST_X(location), ST_Y(location), Extract('year' FROM birthdate)/100000); CREATE INDEX users_loc_age_gix ON users USING GIST (loc_age gist_geometry_ops_nd); tantanapp.com 24
  • 25. Updated query SELECT * FROM users WHERE loc_age &&& ST_MakeLine( ST_MakePoint(180, 90, Extract('year' FROM Now() - interval '74 years')/100000), ST_MakePoint(-180, -90, Extract('year' FROM Now() - interval '75 years')/100000)) ORDER BY loc_age <<->> ST_MakePoint(103.8, 1.3, 0) LIMIT 10; tantanapp.com 25
  • 26. Looking at the execution plan we can see that all is good Limit (cost=0.41..8.43 rows=1 width=136) (actual time=15.294..16.082 rows=10 loops=1) -> Index Scan using users_loc_age_gix on users (cost=0.41..8.43 rows=1 width=136) (actual time=14.685..14.948 rows=10 loops=1) Index Cond: (loc_age &&& 'XXX'::geometry) Order By: (loc_age <<->> 'XXX'::geometry) Planning time: 0.332 ms Execution time: 19.053 ms tantanapp.com 26
  • 27. Looking at the result we see that something is wrong UserID Age 6827677 74 years 11 mons 7 days 1281456 75 years 15 days 1269119 73 years 7 mons 27 days 5791734 73 years 7 mons 8 days 3875002 74 years 7 mons 14 days 6373179 73 years 5 mons 8 days 3727434 74 years 7 mons 21 days 5214330 74 years 10 days 3127049 74 years 8 mons 22 days 6390900 74 years 21 days tantanapp.com 27
  • 28. Solution: Keep the non-geometry where statement SELECT * FROM users WHERE age(birthdate) BETWEEN '74 years' AND '75 years' AND loc_age &&& ST_MakeLine( ST_MakePoint(180, 90, Extract('year' FROM Now() - interval '74 years')/100000), ST_MakePoint(-180, -90, Extract('year' FROM Now() - interval '75 years')/100000)) ORDER BY loc_age <<->> ST_MakePoint(103.8, 1.3, 0) LIMIT 10; tantanapp.com 28
  • 29. Finally we look at Activity 1. Popularity 2. Age 3. Activity <-- tantanapp.com 29
  • 30. Order by last active time WITH x AS (SELECT * FROM users ORDER BY location <-> ST_MakePoint(103.8, 1.3) LIMIT 100) SELECT * FROM x ORDER BY ST_Distance(location::geography, ST_MakePoint(103.8, 1.3)) * Extract(Now() - active_time) LIMIT 10; tantanapp.com 30
  • 31. What is the difference between time, popularity and age? • Popularity is bounded, a users popularity can range between 0 and 1. • Age is also bounded, and static. All our users are between 16 and 100 years old and their birthdate never change. • Time increase infinitely in one direction. tantanapp.com 31
  • 32. Adding time to the geo column ALTER TABLE users ADD COLUMN loc_active geometry; UPDATE users SET loc_active = ST_MakePoint(ST_X(location), ST_Y(location), Extract('epoch' FROM active_time) / 60 / 10000); CREATE INDEX users_loc_active_gix ON users USING GIST (loc_active gist_geometry_ops_nd); tantanapp.com 32
  • 33. Select with time becomes SELECT * FROM users ORDER BY loc_active <<->> ST_MakePoint(103.8, 1.3, Extract('epoch' FROM Now()) / 60 / 10000) LIMIT 10; tantanapp.com 33
  • 34. What we talked about so far 1. Location X and Y 2. Popularity 3. Age 4. Activity tantanapp.com 34
  • 35. Adding a 4th dimension ALTER TABLE users ADD COLUMN loc_pop_age geometry; UPDATE users SET loc_pop_age = ST_MakePoint(ST_X(location), ST_Y(location), 0.01 * 1 / (popularity+1), Extract('year' FROM birthdate)/100000); CREATE INDEX users_loc_pop_age_gix ON users USING GIST (loc_pop_age gist_geometry_ops_nd); tantanapp.com 35
  • 36. Adding a 4th dimension - Query SELECT * FROM users WHERE loc_pop_age &&& ST_MakeLine( ST_MakePoint(180, 90, -100, Extract('year' FROM Now() - interval '20 years')/100000), ST_MakePoint(-180, -90, 100, Extract('year' FROM Now() - interval '30 years')/100000)) ORDER BY loc_pop_age <<->> ST_MakePoint(103.8, 1.3, 0, 0) LIMIT 10; tantanapp.com 36
  • 37. Query runtimes 2D vs 3D vs 4D tantanapp.com 37 0 10 20 30 40 50 Location Location + popularity Location + age (20-30) Location + age (74) Location + activity Location + pop + age (4D) 3D/4D index (ms) 2D index (ms)
  • 38. Query times did not impress. What about index sizes? tantanapp.com 38 0 50 100 150 200 users_pkey users_location_gix users_loc_pop_gix users_loc_pop_age_gix users_loc_age_gix users_loc_active_gix Size bloated (MB) Size fresh(MB)
  • 39. Conclusion 1. Popularity • Pro: Improves ranking? • Con: Makes it more difficult to reason about the ranking formula • Con: Makes the query slower 2. Age • Pro: Fixes query time of outlier queries • Con: Make the average query time longer • Con: Have to take special care to not disturb the normal ranking 3. Time • Pro: Improves ranking? • Con: Much more difficult to reason about the ranking formula • Con: Makes the query slower tantanapp.com 39
  • 40. Conclusion Its more difficult to use the 3rd and 4th dimension than what a quick glance reveals. Test extensively! tantanapp.com 40