Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12...

146
Parted ways With Partitioning? It’s time to reconsider: How PostgreSQL Revived Partitioning to Improve Database Performance Feike Steenbergen Software Engineer, Timescale [email protected] · github.com/timescale

Transcript of Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12...

Page 1: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Parted ways With Partitioning?It’s time to reconsider:How PostgreSQL Revived Partitioning to Improve Database Performance

Feike Steenbergen

Software Engineer, Timescale

[email protected] · github.com/timescale

Page 2: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning

What?

Page 3: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning?

• Split up a table into multiple parts

Page 4: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning?

• Split up a table into multiple parts• Increases manageability of large tables

Page 5: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning?

• Split up a table into multiple parts• Increases manageability of large tables• Can increase performance

Page 6: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning?

• Split up a table into multiple parts• Increases manageability of large tables• Can increase performance• In a distributed setting: allows horizontal scaling

Page 7: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning

How?

Page 8: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Older

Page 9: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Older

Page 10: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Older

Page 11: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Time Based Partitioning

Partitioning

Time

Page 12: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Time Based Partitioning

Partitioning

Time

When: 2019, week 31

Page 13: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Time based and Source based partitioning

2-dimensionalPartitioning

Time

Sou

rce

Cat

egor

y

Page 14: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Time based and Source based partitioning

Time

Sou

rce

Cat

egor

y

2-dimensionalPartitioning

Source: IndustryWhen: 2019, week 31

Page 15: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning

You need a problem first

Page 16: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Very large tables (> 1 TB)

Page 17: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Very large tables (> 1 TB)○ Vacuum takes days (every few days)

Page 18: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Very large tables (> 1 TB)○ Vacuum takes days (every few days)○ (re)index takes very long

Page 19: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Very large tables (> 1 TB)○ Vacuum takes days (every few days)○ (re)index takes very long○ Any incident with this table will be hairy

Page 20: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Data deletion policies

Page 21: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Data deletion policies○ DELETE takes a very, very long time

Page 22: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Data deletion policies○ DELETE takes a very, very long time○ Generates a lot of WAL

Page 23: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Data deletion policies○ DELETE takes a very, very long time○ Generates a lot of WAL○ Data is (no longer) clustered

Page 24: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Problems

• Data deletion policies○ DELETE takes a very, very long time○ Generates a lot of WAL○ Data is (no longer) clustered○ Vacuum takes longer

Page 25: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning

Recent history

Page 26: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

PostgreSQL < 10

Use Inheritance

Page 27: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Increased Query Planning Time

More locks needed

You must create new partitions

Some Foreign Key support

Trigger maintenance

Write manual check constraints

Partitions can overlap

Update does not move rows

No shared (unique) index

Inheritance with PostgreSQL 9.6

Decreased Query execution time

Data retention/tiering is fast

Vacuum/analyze/reindex is faster

Partitions can be on a foreign server

Page 28: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

PostgreSQL 10

Declarative PartitioningHuge speedup on inserts

Page 29: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Increased Query Planning Time

More locks needed

You must create new partitions

No Foreign Key support

Trigger maintenance

Write manual check constraints

Partitions can overlap

Update does not move rows

No shared (unique) index

Partitioning with PostgreSQL 10

Decreased Query execution time

Data retention/tiering is fast

Vacuum/analyze/reindex is faster

Partitions can be on a foreign server

Declarative Partitioning

Page 30: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

PostgreSQL 11

Features, features, features

Page 31: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Increased Query Planning Time

More locks needed

You must create new partitions

No Foreign Key support*

Update does not move rows

No shared (unique) index

Partitioning with PostgreSQL 11

Decreased Query execution time

Data retention/tiering is fast

Vacuum/analyze/reindex is faster

Partitions can be on a foreign server

Declarative Partitioning

Hash Partitioning

Partition Pruning at Init/Execute time

Page 32: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

PostgreSQL 12

Features and Performance

Page 33: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Increased Query Planning Time

More locks needed

You must create new partitions

No Foreign Key support

Partitioning with PostgreSQL 12

Decreased Query execution time

Data retention/tiering is fast

Vacuum/analyze/reindex is faster

Partitions can be on a foreign server

Declarative Partitioning

Hash Partitioning

Partition Pruning at Init/Execute time

Faster COPY support

Catalog improvements (tablespace, pg_indexes)

Full Foreign Key support

Page 34: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Foreign Keys

And why it matters

Page 35: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

order_id: int64line_no: int

order_line

order_id: int64customer_id: int64

order

customer_id: int64

customer

Page 36: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

order_id: int64line_no: int

order_line

customer_id: int64

customer

partition 1

partition 2

order_id: int64customer_id: int64

order

partition n

partition 2

partition 1

partition n

partition 1

9.6: 1 FK for every partition

Page 37: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

order_id: int64line_no: int

order_line

customer_id: int64

customer

partition 1

partition 2

partition n

partition 2

partition 1

partition n

partition 1

10: No Foreign Keys!

order_id: int64customer_id: int64

order

Page 38: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

order_id: int64line_no: int

order_line

customer_id: int64

customer

partition 1

partition 2

partition n

partition 2

partition 1

partition n

partition 1

order_id: int64customer_id: int64

order

11: Foreign Keys from partitioned table to regular table

Page 39: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partition 3

partition 2

order_id: int64line_no: int

order_line

order_id: int64customer_id: int64

order

customer_id: int64

customer

partition 1

partition 2

partition n

partition 2

partition 1

partition n

partition 1

12: Full support for foreign keys

Page 40: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partition 3

partition 2

order_id: int64line_no: int

order_line

order_id: int64customer_id: int64

order

customer_id: int64

customer

partition 1

partition 2

partition n

partition 2

partition 1

partition n

partition 1

12: Full support for foreign keysThis is great!

Page 41: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Insert performance

Gone are the triggers

Page 42: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

IF ( NEW.id >= 24750000 AND NEW.id < 25000000)THEN INSERT INTO hackernews_p0099 VALUES (NEW.*);

-- 98 more IF THEN statements

ELSIF ( NEW.id >= 0 AND NEW.id < 250000)THEN INSERT INTO hackernews_p0000 VALUES (NEW.*);ELSE RAISE EXCEPTION 'Partition hackernews_p% does not yet exist.', NEW.id/250000;END IF;RETURN NULL;

Example trigger

Page 43: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

IF ( NEW.id >= 24750000 AND NEW.id < 25000000)THEN INSERT INTO hackernews_p0099 VALUES (NEW.*);ELSIF ( NEW.id >= 24500000 AND NEW.id < 24750000)THEN INSERT INTO hackernews_p0098 VALUES (NEW.*);ELSIF ( NEW.id >= 24250000 AND NEW.id < 24500000)THEN INSERT INTO hackernews_p0097 VALUES (NEW.*);ELSIF ( NEW.id >= 24000000 AND NEW.id < 24250000)THEN INSERT INTO hackernews_p0096 VALUES (NEW.*);ELSIF ( NEW.id >= 23750000 AND NEW.id < 24000000)THEN INSERT INTO hackernews_p0095 VALUES (NEW.*);ELSIF ( NEW.id >= 23500000 AND NEW.id < 23750000)THEN INSERT INTO hackernews_p0094 VALUES (NEW.*);ELSIF ( NEW.id >= 23250000 AND NEW.id < 23500000)THEN INSERT INTO hackernews_p0093 VALUES (NEW.*);ELSIF ( NEW.id >= 23000000 AND NEW.id < 23250000)THEN INSERT INTO hackernews_p0092 VALUES (NEW.*);ELSIF ( NEW.id >= 22750000 AND NEW.id < 23000000)THEN INSERT INTO hackernews_p0091 VALUES (NEW.*);ELSIF ( NEW.id >= 22500000 AND NEW.id < 22750000)THEN INSERT INTO hackernews_p0090 VALUES (NEW.*);ELSIF ( NEW.id >= 22250000 AND NEW.id < 22500000)THEN INSERT INTO hackernews_p0089 VALUES (NEW.*);ELSIF ( NEW.id >= 22000000 AND NEW.id < 22250000)THEN INSERT INTO hackernews_p0088 VALUES (NEW.*);ELSIF ( NEW.id >= 21750000 AND NEW.id < 22000000)THEN INSERT INTO hackernews_p0087 VALUES (NEW.*);ELSIF ( NEW.id >= 21500000 AND NEW.id < 21750000)THEN INSERT INTO hackernews_p0086 VALUES (NEW.*);ELSIF ( NEW.id >= 21250000 AND NEW.id < 21500000)THEN INSERT INTO hackernews_p0085 VALUES (NEW.*);ELSIF ( NEW.id >= 21000000 AND NEW.id < 21250000)THEN INSERT INTO hackernews_p0084 VALUES (NEW.*);ELSIF ( NEW.id >= 20750000 AND NEW.id < 21000000)THEN INSERT INTO hackernews_p0083 VALUES (NEW.*);ELSIF ( NEW.id >= 20500000 AND NEW.id < 20750000)THEN INSERT INTO hackernews_p0082 VALUES (NEW.*);ELSIF ( NEW.id >= 20250000 AND NEW.id < 20500000)THEN INSERT INTO hackernews_p0081 VALUES (NEW.*);ELSIF ( NEW.id >= 20000000 AND NEW.id < 20250000)THEN INSERT INTO hackernews_p0080 VALUES (NEW.*);ELSIF ( NEW.id >= 19750000 AND NEW.id < 20000000)THEN INSERT INTO hackernews_p0079 VALUES (NEW.*);ELSIF ( NEW.id >= 19500000 AND NEW.id < 19750000)THEN INSERT INTO hackernews_p0078 VALUES (NEW.*);ELSIF ( NEW.id >= 19250000 AND NEW.id < 19500000)THEN INSERT INTO hackernews_p0077 VALUES (NEW.*);ELSIF ( NEW.id >= 19000000 AND NEW.id < 19250000)THEN INSERT INTO hackernews_p0076 VALUES (NEW.*);ELSIF ( NEW.id >= 18750000 AND NEW.id < 19000000)THEN INSERT INTO hackernews_p0075 VALUES (NEW.*);ELSIF ( NEW.id >= 18500000 AND NEW.id < 18750000)THEN INSERT INTO hackernews_p0074 VALUES (NEW.*);ELSIF ( NEW.id >= 18250000 AND NEW.id < 18500000)THEN INSERT INTO hackernews_p0073 VALUES (NEW.*);ELSIF ( NEW.id >= 18000000 AND NEW.id < 18250000)THEN INSERT INTO hackernews_p0072 VALUES (NEW.*);ELSIF ( NEW.id >= 17750000 AND NEW.id < 18000000)THEN INSERT INTO hackernews_p0071 VALUES (NEW.*);ELSIF ( NEW.id >= 17500000 AND NEW.id < 17750000)THEN INSERT INTO hackernews_p0070 VALUES (NEW.*);ELSIF ( NEW.id >= 17250000 AND NEW.id < 17500000)THEN INSERT INTO hackernews_p0069 VALUES (NEW.*);ELSIF ( NEW.id >= 17000000 AND NEW.id < 17250000)THEN INSERT INTO hackernews_p0068 VALUES (NEW.*);ELSIF ( NEW.id >= 16750000 AND NEW.id < 17000000)THEN INSERT INTO hackernews_p0067 VALUES (NEW.*);ELSIF ( NEW.id >= 16500000 AND NEW.id < 16750000)THEN INSERT INTO hackernews_p0066 VALUES (NEW.*);

ELSIF ( NEW.id >= 16250000 AND NEW.id < 16500000)THEN INSERT INTO hackernews_p0065 VALUES (NEW.*);ELSIF ( NEW.id >= 16000000 AND NEW.id < 16250000)THEN INSERT INTO hackernews_p0064 VALUES (NEW.*);ELSIF ( NEW.id >= 15750000 AND NEW.id < 16000000)THEN INSERT INTO hackernews_p0063 VALUES (NEW.*);ELSIF ( NEW.id >= 15500000 AND NEW.id < 15750000)THEN INSERT INTO hackernews_p0062 VALUES (NEW.*);ELSIF ( NEW.id >= 15250000 AND NEW.id < 15500000)THEN INSERT INTO hackernews_p0061 VALUES (NEW.*);ELSIF ( NEW.id >= 15000000 AND NEW.id < 15250000)THEN INSERT INTO hackernews_p0060 VALUES (NEW.*);ELSIF ( NEW.id >= 14750000 AND NEW.id < 15000000)THEN INSERT INTO hackernews_p0059 VALUES (NEW.*);ELSIF ( NEW.id >= 14500000 AND NEW.id < 14750000)THEN INSERT INTO hackernews_p0058 VALUES (NEW.*);ELSIF ( NEW.id >= 14250000 AND NEW.id < 14500000)THEN INSERT INTO hackernews_p0057 VALUES (NEW.*);ELSIF ( NEW.id >= 14000000 AND NEW.id < 14250000)THEN INSERT INTO hackernews_p0056 VALUES (NEW.*);ELSIF ( NEW.id >= 13750000 AND NEW.id < 14000000)THEN INSERT INTO hackernews_p0055 VALUES (NEW.*);ELSIF ( NEW.id >= 13500000 AND NEW.id < 13750000)THEN INSERT INTO hackernews_p0054 VALUES (NEW.*);ELSIF ( NEW.id >= 13250000 AND NEW.id < 13500000)THEN INSERT INTO hackernews_p0053 VALUES (NEW.*);ELSIF ( NEW.id >= 13000000 AND NEW.id < 13250000)THEN INSERT INTO hackernews_p0052 VALUES (NEW.*);ELSIF ( NEW.id >= 12750000 AND NEW.id < 13000000)THEN INSERT INTO hackernews_p0051 VALUES (NEW.*);ELSIF ( NEW.id >= 12500000 AND NEW.id < 12750000)THEN INSERT INTO hackernews_p0050 VALUES (NEW.*);ELSIF ( NEW.id >= 12250000 AND NEW.id < 12500000)THEN INSERT INTO hackernews_p0049 VALUES (NEW.*);ELSIF ( NEW.id >= 12000000 AND NEW.id < 12250000)THEN INSERT INTO hackernews_p0048 VALUES (NEW.*);ELSIF ( NEW.id >= 11750000 AND NEW.id < 12000000)THEN INSERT INTO hackernews_p0047 VALUES (NEW.*);ELSIF ( NEW.id >= 11500000 AND NEW.id < 11750000)THEN INSERT INTO hackernews_p0046 VALUES (NEW.*);ELSIF ( NEW.id >= 11250000 AND NEW.id < 11500000)THEN INSERT INTO hackernews_p0045 VALUES (NEW.*);ELSIF ( NEW.id >= 11000000 AND NEW.id < 11250000)THEN INSERT INTO hackernews_p0044 VALUES (NEW.*);ELSIF ( NEW.id >= 10750000 AND NEW.id < 11000000)THEN INSERT INTO hackernews_p0043 VALUES (NEW.*);ELSIF ( NEW.id >= 10500000 AND NEW.id < 10750000)THEN INSERT INTO hackernews_p0042 VALUES (NEW.*);ELSIF ( NEW.id >= 10250000 AND NEW.id < 10500000)THEN INSERT INTO hackernews_p0041 VALUES (NEW.*);ELSIF ( NEW.id >= 10000000 AND NEW.id < 10250000)THEN INSERT INTO hackernews_p0040 VALUES (NEW.*);ELSIF ( NEW.id >= 9750000 AND NEW.id < 10000000)THEN INSERT INTO hackernews_p0039 VALUES (NEW.*);ELSIF ( NEW.id >= 9500000 AND NEW.id < 9750000)THEN INSERT INTO hackernews_p0038 VALUES (NEW.*);ELSIF ( NEW.id >= 9250000 AND NEW.id < 9500000)THEN INSERT INTO hackernews_p0037 VALUES (NEW.*);ELSIF ( NEW.id >= 9000000 AND NEW.id < 9250000)THEN INSERT INTO hackernews_p0036 VALUES (NEW.*);ELSIF ( NEW.id >= 8750000 AND NEW.id < 9000000)THEN INSERT INTO hackernews_p0035 VALUES (NEW.*);ELSIF ( NEW.id >= 8500000 AND NEW.id < 8750000)THEN INSERT INTO hackernews_p0034 VALUES (NEW.*);ELSIF ( NEW.id >= 8250000 AND NEW.id < 8500000)THEN INSERT INTO hackernews_p0033 VALUES (NEW.*);ELSIF ( NEW.id >= 8000000 AND NEW.id < 8250000)THEN INSERT INTO hackernews_p0032 VALUES (NEW.*);

ELSIF ( NEW.id >= 7750000 AND NEW.id < 8000000)THEN INSERT INTO hackernews_p0031 VALUES (NEW.*);ELSIF ( NEW.id >= 7500000 AND NEW.id < 7750000)THEN INSERT INTO hackernews_p0030 VALUES (NEW.*);ELSIF ( NEW.id >= 7250000 AND NEW.id < 7500000)THEN INSERT INTO hackernews_p0029 VALUES (NEW.*);ELSIF ( NEW.id >= 7000000 AND NEW.id < 7250000)THEN INSERT INTO hackernews_p0028 VALUES (NEW.*);ELSIF ( NEW.id >= 6750000 AND NEW.id < 7000000)THEN INSERT INTO hackernews_p0027 VALUES (NEW.*);ELSIF ( NEW.id >= 6500000 AND NEW.id < 6750000)THEN INSERT INTO hackernews_p0026 VALUES (NEW.*);ELSIF ( NEW.id >= 6250000 AND NEW.id < 6500000)THEN INSERT INTO hackernews_p0025 VALUES (NEW.*);ELSIF ( NEW.id >= 6000000 AND NEW.id < 6250000)THEN INSERT INTO hackernews_p0024 VALUES (NEW.*);ELSIF ( NEW.id >= 5750000 AND NEW.id < 6000000)THEN INSERT INTO hackernews_p0023 VALUES (NEW.*);ELSIF ( NEW.id >= 5500000 AND NEW.id < 5750000)THEN INSERT INTO hackernews_p0022 VALUES (NEW.*);ELSIF ( NEW.id >= 5250000 AND NEW.id < 5500000)THEN INSERT INTO hackernews_p0021 VALUES (NEW.*);ELSIF ( NEW.id >= 5000000 AND NEW.id < 5250000)THEN INSERT INTO hackernews_p0020 VALUES (NEW.*);ELSIF ( NEW.id >= 4750000 AND NEW.id < 5000000)THEN INSERT INTO hackernews_p0019 VALUES (NEW.*);ELSIF ( NEW.id >= 4500000 AND NEW.id < 4750000)THEN INSERT INTO hackernews_p0018 VALUES (NEW.*);ELSIF ( NEW.id >= 4250000 AND NEW.id < 4500000)THEN INSERT INTO hackernews_p0017 VALUES (NEW.*);ELSIF ( NEW.id >= 4000000 AND NEW.id < 4250000)THEN INSERT INTO hackernews_p0016 VALUES (NEW.*);ELSIF ( NEW.id >= 3750000 AND NEW.id < 4000000)THEN INSERT INTO hackernews_p0015 VALUES (NEW.*);ELSIF ( NEW.id >= 3500000 AND NEW.id < 3750000)THEN INSERT INTO hackernews_p0014 VALUES (NEW.*);ELSIF ( NEW.id >= 3250000 AND NEW.id < 3500000)THEN INSERT INTO hackernews_p0013 VALUES (NEW.*);ELSIF ( NEW.id >= 3000000 AND NEW.id < 3250000)THEN INSERT INTO hackernews_p0012 VALUES (NEW.*);ELSIF ( NEW.id >= 2750000 AND NEW.id < 3000000)THEN INSERT INTO hackernews_p0011 VALUES (NEW.*);ELSIF ( NEW.id >= 2500000 AND NEW.id < 2750000)THEN INSERT INTO hackernews_p0010 VALUES (NEW.*);ELSIF ( NEW.id >= 2250000 AND NEW.id < 2500000)THEN INSERT INTO hackernews_p0009 VALUES (NEW.*);ELSIF ( NEW.id >= 2000000 AND NEW.id < 2250000)THEN INSERT INTO hackernews_p0008 VALUES (NEW.*);ELSIF ( NEW.id >= 1750000 AND NEW.id < 2000000)THEN INSERT INTO hackernews_p0007 VALUES (NEW.*);ELSIF ( NEW.id >= 1500000 AND NEW.id < 1750000)THEN INSERT INTO hackernews_p0006 VALUES (NEW.*);ELSIF ( NEW.id >= 1250000 AND NEW.id < 1500000)THEN INSERT INTO hackernews_p0005 VALUES (NEW.*);ELSIF ( NEW.id >= 1000000 AND NEW.id < 1250000)THEN INSERT INTO hackernews_p0004 VALUES (NEW.*);ELSIF ( NEW.id >= 750000 AND NEW.id < 1000000)THEN INSERT INTO hackernews_p0003 VALUES (NEW.*);ELSIF ( NEW.id >= 500000 AND NEW.id < 750000)THEN INSERT INTO hackernews_p0002 VALUES (NEW.*);ELSIF ( NEW.id >= 250000 AND NEW.id < 500000)THEN INSERT INTO hackernews_p0001 VALUES (NEW.*);ELSIF ( NEW.id >= 0 AND NEW.id < 250000)THEN INSERT INTO hackernews_p0000 VALUES (NEW.*);ELSE RAISE EXCEPTION 'Partition hackernews_p% does not yet exist.', NEW.id/250000;END IF;RETURN NULL;

Full example trigger

Page 44: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

query | calls (10) | total time (10) | calls (9.6) | total time (9.6) -------+------------+-----------------+-------------+-----------------COPY | 4 | 00:03:19.7 | 4 | 01:15:11.6INSERT | (null) | (null) | 37004321 | 00:05:00.6VACUUM | 1 | 00:02:15.3 | 1 | 00:01:53CREATE | 1484 | 00:00:46.1 | 13138 | 00:00:40.8ALTER | 186 | 00:00:15.7 | 647 | 00:00:15.4

pg_stat_statements: 9.6 vs 10

Page 45: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

query | calls (10) | total time (10) | calls (9.6) | total time (9.6) -------+------------+-----------------+-------------+-----------------COPY | 4 | 00:03:19.7 | 4 | 01:15:11.6INSERT | (null) | (null) | 37004321 | 00:05:00.6VACUUM | 1 | 00:02:15.3 | 1 | 00:01:53CREATE | 1484 | 00:00:46.1 | 13138 | 00:00:40.8ALTER | 186 | 00:00:15.7 | 647 | 00:00:15.4

pg_stat_statements: 9.6 vs 10

23 times faster

Page 46: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Explain

Verify your assumptions

Page 47: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Planner

Plan A Plan B Plan C

Page 48: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Explain

Plan A Plan B Plan C

Page 49: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Explain (analyze on)

Plan A Plan B Plan C

Page 50: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Datasets● US Environmental Protection Agency.

Air Quality System Data Marthttps://console.cloud.google.com/bigquery?p=bigquery-public-data&d=epa_historical_air_quality&page=dataset

● All stories and comments from Hacker News from its launch in 2006 to presenthttps://console.cloud.google.com/bigquery?p=bigquery-public-data&d=hacker_news&page=dataset

Page 51: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partitioning deep dive

Aggregate Query

Page 52: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

SELECT date_local, state_name, max(first_max_value) AS first_max_valueFROM epa_temperature_daily_summaryGROUP BY date_local, state_name

Aggregate Query

Page 53: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

GroupAggregate (actual rows=431338 loops=1) Group Key: date_local, state_name Buffers: shared read=230346, temp read=35767 written=35824 I/O Timings: read=10278.527 -> Sort (actual rows=6017246 loops=1) Sort Key: date_local, state_name Sort Method: external merge Disk: 192864kB -> Seq Scan on epa_temperature_daily_summary (actual rows=6017246 loops=1)

Planning Time: 1.642 ms Execution Time: 59380.914 ms

1 single table (PostgreSQL 12)

Page 54: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

GroupAggregate (actual rows=431338 loops=1) Group Key: date_local, state_name Buffers: shared read=230346, temp read=35767 written=35824 I/O Timings: read=10278.527 -> Sort (actual rows=6017246 loops=1) Sort Key: date_local, state_name Sort Method: external merge Disk: 192864kB -> Seq Scan on epa_temperature_daily_summary (actual rows=6017246 loops=1)

Planning Time: 1.642 ms Execution Time: 59380.914 ms

1 single table (PostgreSQL 12)

Page 55: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

GroupAggregate (actual rows=431338 loops=1) Group Key: date_local, state_name Buffers: shared read=230346, temp read=35767 written=35824 I/O Timings: read=10278.527 -> Sort (actual rows=6017246 loops=1) Sort Key: date_local, state_name Sort Method: external merge Disk: 192864kB -> Seq Scan on epa_temperature_daily_summary (actual rows=6017246 loops=1)

Planning Time: 1.642 ms Execution Time: 59380.914 ms

1 single table (PostgreSQL 12)

Page 56: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

GroupAggregate (actual rows=431338 loops=1) Group Key: date_local, state_name Buffers: shared read=230346, temp read=35767 written=35824 I/O Timings: read=10278.527 -> Sort (actual rows=6017246 loops=1) Sort Key: date_local, state_name Sort Method: external merge Disk: 192864kB -> Seq Scan on epa_temperature_daily_summary (actual rows=6017246 loops=1)

Planning Time: 1.642 ms Execution Time: 59380.914 ms

1 single table (PostgreSQL 12)

Page 57: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

GroupAggregate (actual rows=431338 loops=1) Group Key: date_local, state_name Buffers: shared read=230346, temp read=35767 written=35824 I/O Timings: read=10278.527 -> Sort (actual rows=6017246 loops=1) Sort Key: date_local, state_name Sort Method: external merge Disk: 192864kB -> Seq Scan on epa_temperature_daily_summary (actual rows=6017246 loops=1)

Planning Time: 1.642 ms Execution Time: 59380.914 ms

1 single table (PostgreSQL 12)

Page 58: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partitioned table (PostgreSQL 12)

GroupAggregate (actual rows=431338 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=230406, temp read=35766 written=35823 I/O Timings: read=10640.559 -> Sort (actual rows=6017246 loops=1) Sort Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Sort Method: external merge Disk: 192856kB -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1)

Planning Time: 29.489 ms Execution Time: 59515.809 ms

Page 59: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partitioned table (PostgreSQL 12)

GroupAggregate (actual rows=431338 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=230406, temp read=35766 written=35823 I/O Timings: read=10640.559 -> Sort (actual rows=6017246 loops=1) Sort Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Sort Method: external merge Disk: 192856kB -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1)

Planning Time: 29.489 ms Execution Time: 59515.809 ms

Page 60: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partitioned table (PostgreSQL 12)

GroupAggregate (actual rows=431338 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=230406, temp read=35766 written=35823 I/O Timings: read=10640.559 -> Sort (actual rows=6017246 loops=1) Sort Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Sort Method: external merge Disk: 192856kB -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1)

Planning Time: 29.489 ms Execution Time: 59515.809 ms

Page 61: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partitioned table (PostgreSQL 12)

GroupAggregate (actual rows=431338 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=230406, temp read=35766 written=35823 I/O Timings: read=10640.559 -> Sort (actual rows=6017246 loops=1) Sort Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Sort Method: external merge Disk: 192856kB -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1)

Planning Time: 29.489 ms Execution Time: 59515.809 ms

Page 62: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partitioned table (PostgreSQL 12)

GroupAggregate (actual rows=431338 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=230406, temp read=35766 written=35823 I/O Timings: read=10640.559 -> Sort (actual rows=6017246 loops=1) Sort Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Sort Method: external merge Disk: 192856kB -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1)

Planning Time: 29.489 ms Execution Time: 59515.809 ms

Page 63: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partitioned table (PostgreSQL 12)

GroupAggregate (actual rows=431338 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=230406, temp read=35766 written=35823 I/O Timings: read=10640.559 -> Sort (actual rows=6017246 loops=1) Sort Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Sort Method: external merge Disk: 192856kB -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1)

Planning Time: 29.489 ms Execution Time: 59515.809 ms

Page 64: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

partitioned table (PostgreSQL 12)

GroupAggregate (actual rows=431338 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=230406, temp read=35766 written=35823 I/O Timings: read=10640.559 -> Sort (actual rows=6017246 loops=1) Sort Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Sort Method: external merge Disk: 192856kB -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1)

Planning Time: 29.489 ms Execution Time: 59515.809 ms

Page 65: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=230346temp read=35767written=35824

I/O Timings: read=10278.527

Planning Time: 1.642 msExecution Time: 59380.914 ms

Buffers:shared read=230406temp read=35766written=35823

I/O Timings: read=10640.559

Planning Time: 29.489 msExecution Time: 59515.809 ms

Single table Partitioned

Page 66: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=230346temp read=35767written=35824

I/O Timings: read=10278.527

Planning Time: 1.642 msExecution Time: 59380.914 ms

Buffers:shared read=230406temp read=35766written=35823

I/O Timings: read=10640.559

Planning Time: 29.489 msExecution Time: 59515.809 ms

Single table Partitioned

Page 67: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Sort and AggregatePartition

Single table

Page 68: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Sort and AggregatePartition

Single table Partitioned

Page 69: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

SET enable_partitionwise_aggregate TO 'on';

Enable Partitionwise Aggregate

https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-ENABLE-PARTITIONWISE-AGGREGATE

Page 70: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=431338 loops=1) Buffers: shared read=230406 I/O Timings: read=7771.143 -> HashAggregate (actual rows=2226 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=731 -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) Buffers: shared read=731 -> HashAggregate (actual rows=2208 loops=1) Group Key: epa_temperature_daily_summary_y1990q2.date_local, epa_temperature_daily_summary_y1990q2.state_name Buffers: shared read=754 -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1) Buffers: shared read=754

Planning Time: 31.801 ms Execution Time: 35134.950 ms

Partitionwise Aggregate

Page 71: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=431338 loops=1) Buffers: shared read=230406 I/O Timings: read=7771.143 -> HashAggregate (actual rows=2226 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=731 -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) Buffers: shared read=731 -> HashAggregate (actual rows=2208 loops=1) Group Key: epa_temperature_daily_summary_y1990q2.date_local, epa_temperature_daily_summary_y1990q2.state_name Buffers: shared read=754 -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1) Buffers: shared read=754

Planning Time: 31.801 ms Execution Time: 35134.950 ms

Partitionwise Aggregate

Page 72: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=431338 loops=1) Buffers: shared read=230406 I/O Timings: read=7771.143 -> HashAggregate (actual rows=2226 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=731 -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) Buffers: shared read=731 -> HashAggregate (actual rows=2208 loops=1) Group Key: epa_temperature_daily_summary_y1990q2.date_local, epa_temperature_daily_summary_y1990q2.state_name Buffers: shared read=754 -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1) Buffers: shared read=754

Planning Time: 31.801 ms Execution Time: 35134.950 ms

Partitionwise Aggregate

Page 73: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=431338 loops=1) Buffers: shared read=230406 I/O Timings: read=7771.143 -> HashAggregate (actual rows=2226 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=731 -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) Buffers: shared read=731 -> HashAggregate (actual rows=2208 loops=1) Group Key: epa_temperature_daily_summary_y1990q2.date_local, epa_temperature_daily_summary_y1990q2.state_name Buffers: shared read=754 -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1) Buffers: shared read=754

Planning Time: 31.801 ms Execution Time: 35134.950 ms

Partitionwise Aggregate

Page 74: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=431338 loops=1) Buffers: shared read=230406 I/O Timings: read=7771.143 -> HashAggregate (actual rows=2226 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=731 -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) Buffers: shared read=731 -> HashAggregate (actual rows=2208 loops=1) Group Key: epa_temperature_daily_summary_y1990q2.date_local, epa_temperature_daily_summary_y1990q2.state_name Buffers: shared read=754 -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1) Buffers: shared read=754

Planning Time: 31.801 ms Execution Time: 35134.950 ms

Partitionwise Aggregate

Page 75: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=431338 loops=1) Buffers: shared read=230406 I/O Timings: read=7771.143 -> HashAggregate (actual rows=2226 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=731 -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) Buffers: shared read=731 -> HashAggregate (actual rows=2208 loops=1) Group Key: epa_temperature_daily_summary_y1990q2.date_local, epa_temperature_daily_summary_y1990q2.state_name Buffers: shared read=754 -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1) Buffers: shared read=754

Planning Time: 31.801 ms Execution Time: 35134.950 ms

Partitionwise Aggregate

Page 76: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=431338 loops=1) Buffers: shared read=230406 I/O Timings: read=7771.143 -> HashAggregate (actual rows=2226 loops=1) Group Key: epa_temperature_daily_summary_y1990q1.date_local, epa_temperature_daily_summary_y1990q1.state_name Buffers: shared read=731 -> Seq Scan on epa_temperature_daily_summary_y1990q1 (actual rows=19596 loops=1) Buffers: shared read=731 -> HashAggregate (actual rows=2208 loops=1) Group Key: epa_temperature_daily_summary_y1990q2.date_local, epa_temperature_daily_summary_y1990q2.state_name Buffers: shared read=754 -> Seq Scan on epa_temperature_daily_summary_y1990q2 (actual rows=20232 loops=1) Buffers: shared read=754

Planning Time: 31.801 ms Execution Time: 35134.950 ms

Partitionwise Aggregate

Page 77: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=230346temp read=35767written=35824

I/O Timings: read=10278.527

Planning Time: 1.642 msExecution Time: 59380.914 ms

Buffers:shared read=230406

I/O Timings: read=7771.143

Planning Time: 31.801 msExecution Time: 35134.950 ms

Single table Partitionwise Agg

Page 78: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=230346temp read=35767written=35824

I/O Timings: read=10278.527

Planning Time: 1.642 msExecution Time: 59380.914 ms

Buffers:shared read=230406

I/O Timings: read=7771.143

Planning Time: 31.801 msExecution Time: 35134.950 ms

Single table Partitionwise Agg

Page 79: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=230346temp read=35767written=35824

I/O Timings: read=10278.527

Planning Time: 1.642 msExecution Time: 59380.914 ms

Buffers:shared read=230406

I/O Timings: read=7771.143

Planning Time: 31.801 msExecution Time: 35134.950 ms

Single table Partitionwise Agg

Page 80: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=230346temp read=35767written=35824

I/O Timings: read=10278.527

Planning Time: 1.642 msExecution Time: 59380.914 ms

Buffers:shared read=230406

I/O Timings: read=7771.143

Planning Time: 31.801 msExecution Time: 35134.950 ms

Single table Partitionwise Agg

Page 81: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=230346temp read=35767written=35824

I/O Timings: read=10278.527

Planning Time: 1.642 msExecution Time: 59380.914 ms

Buffers:shared read=230406

I/O Timings: read=7771.143

Planning Time: 31.801 msExecution Time: 35134.950 ms

Single table Partitionwise Agg

Page 82: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=230346temp read=35767written=35824

I/O Timings: read=10278.527

Planning Time: 1.642 msExecution Time: 59380.914 ms

Buffers:shared read=230406

I/O Timings: read=7771.143

Planning Time: 31.801 msExecution Time: 35134.950 ms

Single table Partitionwise Agg

This is great!

Page 83: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Sort and AggregatePartition

Single table Partitioned

Page 84: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Sort and AggregatePartition

Single table PartitionwisePartitioned

Page 85: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

SELECT state_name, county_name, city_name, date_local, pressure.first_max_value, temperature.first_max_valueFROM epa_pressure_daily_summary AS pressureJOIN epa_temperature_daily_summary AS temperature

USING (date_local, state_name, county_name, city_name)

Join

Page 86: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.county_name = pressure.county_name) AND (temperature.date_local = pressure.date_local) AND (temperature.state_name = pres Buffers: shared read=295773, temp read=72382 written=72470 I/O Timings: read=13941.133 -> Sort (actual rows=6017246 loops=1) Sort Key: temperature.county_name, temperature.date_local, temperature.state_name, temperature.city_name Sort Method: external merge Disk: 305376kB -> Seq Scan on epa_temperature_daily_summary temperature (actual rows=6017246 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) Sort Key: pressure.county_name, pressure.date_local, pressure.state_name, pressure.city_name Sort Method: external merge Disk: 94688kB -> Seq Scan on epa_pressure_daily_summary pressure (actual rows=1818026 loops=1)

Planning Time: 34.756 ms Execution Time: 133502.051 ms

Nonpartitioned case

Page 87: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.county_name = pressure.county_name) AND (temperature.date_local = pressure.date_local) AND (temperature.state_name = pres Buffers: shared read=295773, temp read=72382 written=72470 I/O Timings: read=13941.133 -> Sort (actual rows=6017246 loops=1) Sort Key: temperature.county_name, temperature.date_local, temperature.state_name, temperature.city_name Sort Method: external merge Disk: 305376kB -> Seq Scan on epa_temperature_daily_summary temperature (actual rows=6017246 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) Sort Key: pressure.county_name, pressure.date_local, pressure.state_name, pressure.city_name Sort Method: external merge Disk: 94688kB -> Seq Scan on epa_pressure_daily_summary pressure (actual rows=1818026 loops=1)

Planning Time: 34.756 ms Execution Time: 133502.051 ms

Nonpartitioned case

Page 88: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.county_name = pressure.county_name) AND (temperature.date_local = pressure.date_local) AND (temperature.state_name = pres Buffers: shared read=295773, temp read=72382 written=72470 I/O Timings: read=13941.133 -> Sort (actual rows=6017246 loops=1) Sort Key: temperature.county_name, temperature.date_local, temperature.state_name, temperature.city_name Sort Method: external merge Disk: 305376kB -> Seq Scan on epa_temperature_daily_summary temperature (actual rows=6017246 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) Sort Key: pressure.county_name, pressure.date_local, pressure.state_name, pressure.city_name Sort Method: external merge Disk: 94688kB -> Seq Scan on epa_pressure_daily_summary pressure (actual rows=1818026 loops=1)

Planning Time: 34.756 ms Execution Time: 133502.051 ms

Nonpartitioned case

Page 89: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.county_name = pressure.county_name) AND (temperature.date_local = pressure.date_local) AND (temperature.state_name = pres Buffers: shared read=295773, temp read=72382 written=72470 I/O Timings: read=13941.133 -> Sort (actual rows=6017246 loops=1) Sort Key: temperature.county_name, temperature.date_local, temperature.state_name, temperature.city_name Sort Method: external merge Disk: 305376kB -> Seq Scan on epa_temperature_daily_summary temperature (actual rows=6017246 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) Sort Key: pressure.county_name, pressure.date_local, pressure.state_name, pressure.city_name Sort Method: external merge Disk: 94688kB -> Seq Scan on epa_pressure_daily_summary pressure (actual rows=1818026 loops=1)

Planning Time: 34.756 ms Execution Time: 133502.051 ms

Nonpartitioned case

Page 90: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.county_name = pressure.county_name) AND (temperature.date_local = pressure.date_local) AND (temperature.state_name = pres Buffers: shared read=295773, temp read=72382 written=72470 I/O Timings: read=13941.133 -> Sort (actual rows=6017246 loops=1) Sort Key: temperature.county_name, temperature.date_local, temperature.state_name, temperature.city_name Sort Method: external merge Disk: 305376kB -> Seq Scan on epa_temperature_daily_summary temperature (actual rows=6017246 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) Sort Key: pressure.county_name, pressure.date_local, pressure.state_name, pressure.city_name Sort Method: external merge Disk: 94688kB -> Seq Scan on epa_pressure_daily_summary pressure (actual rows=1818026 loops=1)

Planning Time: 34.756 ms Execution Time: 133502.051 ms

Nonpartitioned case

Page 91: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.county_name = pressure.county_name) AND (temperature.date_local = pressure.date_local) AND (temperature.state_name = pres Buffers: shared read=295773, temp read=72382 written=72470 I/O Timings: read=13941.133 -> Sort (actual rows=6017246 loops=1) Sort Key: temperature.county_name, temperature.date_local, temperature.state_name, temperature.city_name Sort Method: external merge Disk: 305376kB -> Seq Scan on epa_temperature_daily_summary temperature (actual rows=6017246 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) Sort Key: pressure.county_name, pressure.date_local, pressure.state_name, pressure.city_name Sort Method: external merge Disk: 94688kB -> Seq Scan on epa_pressure_daily_summary pressure (actual rows=1818026 loops=1)

Planning Time: 34.756 ms Execution Time: 133502.051 ms

Nonpartitioned case

Page 92: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.county_name = pressure.county_name) AND (temperature.date_local = pressure.date_local) AND (temperature.state_name = pres Buffers: shared read=295773, temp read=72382 written=72470 I/O Timings: read=13941.133 -> Sort (actual rows=6017246 loops=1) Sort Key: temperature.county_name, temperature.date_local, temperature.state_name, temperature.city_name Sort Method: external merge Disk: 305376kB -> Seq Scan on epa_temperature_daily_summary temperature (actual rows=6017246 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) Sort Key: pressure.county_name, pressure.date_local, pressure.state_name, pressure.city_name Sort Method: external merge Disk: 94688kB -> Seq Scan on epa_pressure_daily_summary pressure (actual rows=1818026 loops=1)

Planning Time: 34.756 ms Execution Time: 133502.051 ms

Nonpartitioned case

Page 93: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.county_name = pressure.county_name) AND (temperature.date_local = pressure.date_local) AND (temperature.state_name = pres Buffers: shared read=295773, temp read=72382 written=72470 I/O Timings: read=13941.133 -> Sort (actual rows=6017246 loops=1) Sort Key: temperature.county_name, temperature.date_local, temperature.state_name, temperature.city_name Sort Method: external merge Disk: 305376kB -> Seq Scan on epa_temperature_daily_summary temperature (actual rows=6017246 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) Sort Key: pressure.county_name, pressure.date_local, pressure.state_name, pressure.city_name Sort Method: external merge Disk: 94688kB -> Seq Scan on epa_pressure_daily_summary pressure (actual rows=1818026 loops=1)

Planning Time: 34.756 ms Execution Time: 133502.051 ms

Nonpartitioned case

Page 94: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 95: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 96: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 97: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 98: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 99: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 100: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 101: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 102: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 103: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 104: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 105: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Merge Join (actual rows=3863962 loops=1) Merge Cond: ((temperature.date_local = pressure.date_local) AND (temperature.state_name = pressure.state_name) AND (temperature.county_name = press Buffers: shared read=295889, temp read=72380 written=72468 I/O Timings: read=15027.763 -> Sort (actual rows=6017246 loops=1) -> Append (actual rows=6017246 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1) -> Materialize (actual rows=3934054 loops=1) -> Sort (actual rows=1818026 loops=1) -> Append (actual rows=1818026 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1)

Planning Time: 1072.202 ms Execution Time: 113812.905 ms

Large Merge Join of 2 sorted sets

Page 106: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

(inner) joinPartition

Single table⨝

Page 107: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

(inner) joinPartition

Single table Partitioned⨝ ⨝

Page 108: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

SET enable_partitionwise_join TO 'on';

Enable Partitionwise Join

https://www.postgresql.org/docs/current/runtime-config-query.html#GUC-ENABLE-PARTITIONWISE-JOIN

Page 109: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=3863962 loops=1) Buffers: shared read=295889 I/O Timings: read=8642.244 -> Merge Join (actual rows=2783 loops=1) -> Sort (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Sort (actual rows=19636 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Merge Join (actual rows=2794 loops=1) -> Sort (actual rows=1490 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1) -> Sort (actual rows=20252 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1)

Planning Time: 465.177 ms Execution Time: 97487.558 ms

Partitionwise Join

Page 110: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=3863962 loops=1) Buffers: shared read=295889 I/O Timings: read=8642.244 -> Merge Join (actual rows=2783 loops=1) -> Sort (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Sort (actual rows=19636 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Merge Join (actual rows=2794 loops=1) -> Sort (actual rows=1490 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1) -> Sort (actual rows=20252 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1)

Planning Time: 465.177 ms Execution Time: 97487.558 ms

Partitionwise Join

Page 111: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=3863962 loops=1) Buffers: shared read=295889 I/O Timings: read=8642.244 -> Merge Join (actual rows=2783 loops=1) -> Sort (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Sort (actual rows=19636 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Merge Join (actual rows=2794 loops=1) -> Sort (actual rows=1490 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1) -> Sort (actual rows=20252 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1)

Planning Time: 465.177 ms Execution Time: 97487.558 ms

Partitionwise Join

Page 112: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=3863962 loops=1) Buffers: shared read=295889 I/O Timings: read=8642.244 -> Merge Join (actual rows=2783 loops=1) -> Sort (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Sort (actual rows=19636 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Merge Join (actual rows=2794 loops=1) -> Sort (actual rows=1490 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1) -> Sort (actual rows=20252 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1)

Planning Time: 465.177 ms Execution Time: 97487.558 ms

Partitionwise Join

Page 113: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=3863962 loops=1) Buffers: shared read=295889 I/O Timings: read=8642.244 -> Merge Join (actual rows=2783 loops=1) -> Sort (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Sort (actual rows=19636 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Merge Join (actual rows=2794 loops=1) -> Sort (actual rows=1490 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1) -> Sort (actual rows=20252 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1)

Planning Time: 465.177 ms Execution Time: 97487.558 ms

Partitionwise Join

Page 114: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=3863962 loops=1) Buffers: shared read=295889 I/O Timings: read=8642.244 -> Merge Join (actual rows=2783 loops=1) -> Sort (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Sort (actual rows=19636 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Merge Join (actual rows=2794 loops=1) -> Sort (actual rows=1490 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1) -> Sort (actual rows=20252 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1)

Planning Time: 465.177 ms Execution Time: 97487.558 ms

Partitionwise Join

Page 115: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Append (actual rows=3863962 loops=1) Buffers: shared read=295889 I/O Timings: read=8642.244 -> Merge Join (actual rows=2783 loops=1) -> Sort (actual rows=1513 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q1 pressure (actual rows=1513 loops=1) -> Sort (actual rows=19636 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q1 temperature (actual rows=19596 loops=1) -> Merge Join (actual rows=2794 loops=1) -> Sort (actual rows=1490 loops=1) -> Seq Scan on epa_pressure_daily_summary_y1990q2 pressure_1 (actual rows=1490 loops=1) -> Sort (actual rows=20252 loops=1) -> Seq Scan on epa_temperature_daily_summary_y1990q2 temperature_1 (actual rows=20232 loops=1)

Planning Time: 465.177 ms Execution Time: 97487.558 ms

Partitionwise Join

Page 116: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=295773temp read=72382written=72470

I/O Timings: read=13941.133

Planning Time: 34.756 msExecution Time: 133502.051 ms

Buffers:shared read=295889

I/O Timings: read=8642.244

Planning Time: 465.177 msExecution Time: 97487.558 ms

Nonpartitioned Partitionwise Join

Page 117: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=295773temp read=72382written=72470

I/O Timings: read=13941.133

Planning Time: 34.756 msExecution Time: 133502.051 ms

Buffers:shared read=295889

I/O Timings: read=8642.244

Planning Time: 465.177 msExecution Time: 97487.558 ms

Nonpartitioned Partitionwise Join

Page 118: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=295773temp read=72382written=72470

I/O Timings: read=13941.133

Planning Time: 34.756 msExecution Time: 133502.051 ms

Buffers:shared read=295889

I/O Timings: read=8642.244

Planning Time: 465.177 msExecution Time: 97487.558 ms

Nonpartitioned Partitionwise Join

Page 119: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared read=295773temp read=72382written=72470

I/O Timings: read=13941.133

Planning Time: 34.756 msExecution Time: 133502.051 ms

Buffers:shared read=295889

I/O Timings: read=8642.244

Planning Time: 465.177 msExecution Time: 97487.558 ms

Nonpartitioned Partitionwise Join

Page 120: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

(inner) joinPartition

Single table PartitionwisePartitioned⨝ ⨝ ⨝⨝⨝⨝⨝⨝⨝⨝

Page 121: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

(inner) joinPartition

Partitions need to cover the same values though

('1990-07-01') TO ('1990-10-01')('1990-07-01') TO ('1990-10-01')

⨝ ('1990-10-01') TO ('1991-01-01')('1990-10-01') TO ('1991-01-01')

⨝ ('1991-01-01') TO ('1991-04-01')('1991-01-01') TO ('1991-04-01')

⨝ ('2019-07-01') TO ('2019-10-01')('2019-07-01') TO ('2019-10-01')

Page 122: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Partition Pruning

During planning, during initialization, and also during execution

Page 123: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

PREPARE hackernews_parent ASSELECT

*FROM hackernews childJOIN

hackernews parent ON (parent.id=child.parent)WHERE

child.id = $1;

Partition Pruning

Page 124: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=259 read=10 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=258 read=7 -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 parent (actual rows=1 loops=1) -> Index Scan using hackernews_p0001_pkey on hackernews_p0001 parent_1 (actual rows=0 loops=1) -> Index Scan using hackernews_p0002_pkey on hackernews_p0002 parent_2 (actual rows=0 loops=1)

Planning time: 6.187 ms Execution time: 2.636 ms

Partition Pruning: PostgreSQL 10

Page 125: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=259 read=10 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=258 read=7 -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 parent (actual rows=1 loops=1) -> Index Scan using hackernews_p0001_pkey on hackernews_p0001 parent_1 (actual rows=0 loops=1) -> Index Scan using hackernews_p0002_pkey on hackernews_p0002 parent_2 (actual rows=0 loops=1)

Planning time: 6.187 ms Execution time: 2.636 ms

Partition Pruning: PostgreSQL 10

Page 126: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=259 read=10 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=258 read=7 -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 parent (actual rows=1 loops=1) -> Index Scan using hackernews_p0001_pkey on hackernews_p0001 parent_1 (actual rows=0 loops=1) -> Index Scan using hackernews_p0002_pkey on hackernews_p0002 parent_2 (actual rows=0 loops=1)

Planning time: 6.187 ms Execution time: 2.636 ms

Partition Pruning: PostgreSQL 10

Page 127: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=259 read=10 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=258 read=7 -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 parent (actual rows=1 loops=1) -> Index Scan using hackernews_p0001_pkey on hackernews_p0001 parent_1 (actual rows=0 loops=1) -> Index Scan using hackernews_p0002_pkey on hackernews_p0002 parent_2 (actual rows=0 loops=1)

Planning time: 6.187 ms Execution time: 2.636 ms

Partition Pruning: PostgreSQL 10

Page 128: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=259 read=10 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=258 read=7 -> Index Scan [...] (actual rows=1 loops=1) -> Index Scan [...] (actual rows=0 loops=1) -> Index Scan [...] (actual rows=0 loops=1)

Planning time: 6.187 ms Execution time: 2.636 ms

Partition Pruning: PostgreSQL 10

Page 129: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=259 read=10 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=258 read=7 -> Index Scan [...] (actual rows=1 loops=1) -> Index Scan [...] (actual rows=0 loops=1) -> Index Scan [...] (actual rows=0 loops=1)

Planning time: 6.187 ms Execution time: 2.636 ms

Partition Pruning: PostgreSQL 10

Page 130: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=259 read=10 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=258 read=7 -> Index Scan [...] (actual rows=1 loops=1) -> Index Scan [...] (actual rows=0 loops=1) -> Index Scan [...] (actual rows=0 loops=1)

Planning time: 6.187 ms Execution time: 2.636 ms

Partition Pruning: PostgreSQL 10

Page 131: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=8 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=4 -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 parent (actual rows=1 loops=1) -> Index Scan using hackernews_p0001_pkey on hackernews_p0001 parent_1 (never executed) -> Index Scan using hackernews_p0002_pkey on hackernews_p0002 parent_2 (never executed)

Planning Time: 5.856 ms Execution Time: 0.789 ms

Partition Pruning: PostgreSQL 11

Page 132: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=8 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=4 -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 parent (actual rows=1 loops=1) -> Index Scan using hackernews_p0001_pkey on hackernews_p0001 parent_1 (never executed) -> Index Scan using hackernews_p0002_pkey on hackernews_p0002 parent_2 (never executed)

Planning Time: 5.856 ms Execution Time: 0.789 ms

Partition Pruning: PostgreSQL 11

Page 133: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=8 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=4 -> Index Scan [...] (actual rows=1 loops=1) -> Index Scan [...] (never executed) -> Index Scan [...] (never executed)

Planning Time: 5.856 ms Execution Time: 0.789 ms

Partition Pruning: PostgreSQL 11

Page 134: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=8 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=4 -> Index Scan [...] (actual rows=1 loops=1) -> Index Scan [...] (never executed) -> Index Scan [...] (never executed)

Planning Time: 5.856 ms Execution Time: 0.789 ms

Partition Pruning: PostgreSQL 11

Page 135: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Nested Loop (actual rows=1 loops=1) Buffers: shared hit=8 -> Append (actual rows=1 loops=1) -> Index Scan using hackernews_p0000_pkey on hackernews_p0000 child (actual rows=1 loops=1) -> Append (actual rows=1 loops=1) Buffers: shared hit=4 -> Index Scan [...] (actual rows=1 loops=1) -> Index Scan [...] (never executed) -> Index Scan [...] (never executed)

Planning Time: 5.856 ms Execution Time: 0.789 ms

Partition Pruning: PostgreSQL 11

Page 136: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared hit=259 read=10

Planning time: 6.187 msExecution time: 2.636 ms

Buffers:shared hit=8

Planning Time: 5.856 msExecution Time: 0.789 ms

PostgreSQL 10 PostgreSQL 11

Page 137: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared hit=259 read=10

Planning time: 6.187 msExecution time: 2.636 ms

Buffers:shared hit=8

Planning Time: 5.856 msExecution Time: 0.789 ms

PostgreSQL 10 PostgreSQL 11

Page 138: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Buffers:shared hit=259 read=10

Planning time: 6.187 msExecution time: 2.636 ms

Buffers:shared hit=8

Planning Time: 5.856 msExecution Time: 0.789 ms

PostgreSQL 10 PostgreSQL 11

Page 139: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Summary

Page 140: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Summary● Declarative partitioning

Page 141: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Summary● Declarative partitioning● Constraints on schema design are

mostly gone (foreign keys, indexes)

Page 142: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Summary● Declarative partitioning● Constraints on schema design are

mostly gone (foreign keys, indexes)● Potentially (a lot) faster

Page 143: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Summary● Declarative partitioning● Constraints on schema design are

mostly gone (foreign keys, indexes)● Potentially (a lot) faster● Potentially (a lot) less server load

Page 144: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Summary● Declarative partitioning● Constraints on schema design are

mostly gone (foreign keys, indexes)● Potentially (a lot) faster● Potentially (a lot) less server load

This is great!

Page 145: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex
Page 146: Parted ways With Partitioning? Software Engineer, Timescale · Partitioning with PostgreSQL 12 Decreased Query execution time Data retention/tiering is fast Vacuum/analyze/reindex

Questions?

Feike Steenbergen

Software Engineer, Timescale

[email protected] · github.com/timescale