Π ΡΡΠΎΠΌ ΠΈΡΡΠ»Π΅Π΄ΠΎΠ²Π°Π½ΠΈΠΈ Ρ Ρ ΠΎΡΠ΅Π» ΠΏΠΎΡΠΌΠΎΡΡΠ΅ΡΡ, ΠΊΠ°ΠΊΠΈΠ΅ ΡΠ»ΡΡΡΠ΅Π½ΠΈΡ ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΠΈ ΠΌΠΎΠΆΠ½ΠΎ ΠΏΠΎΠ»ΡΡΠΈΡΡ, ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡ ΠΈΡΡΠΎΡΠ½ΠΈΠΊ Π΄Π°Π½Π½ΡΡ ClickHouse, Π° Π½Π΅ PostgreSQL. Π― Π·Π½Π°Ρ, ΠΊΠ°ΠΊΠΈΠ΅ ΠΏΡΠ΅ΠΈΠΌΡΡΠ΅ΡΡΠ²Π° ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΠΈ ΠΏΡΠΈ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠΈ ClickHouse Ρ ΠΏΠΎΠ»ΡΡΠ°Ρ. ΠΡΠ΄ΡΡ Π»ΠΈ ΡΡΠΈ ΠΏΡΠ΅ΠΈΠΌΡΡΠ΅ΡΡΠ²Π° ΡΠΎΡ ΡΠ°Π½Π΅Π½Ρ, Π΅ΡΠ»ΠΈ Ρ ΠΏΠΎΠ»ΡΡΡ Π΄ΠΎΡΡΡΠΏ ΠΊ ClickHouse ΠΈΠ· PostgreSQL Ρ ΠΏΠΎΠΌΠΎΡΡΡ Π²Π½Π΅ΡΠ½Π΅ΠΉ ΠΎΠ±ΠΎΠ»ΠΎΡΠΊΠΈ Π΄Π°Π½Π½ΡΡ (FDW)?
ΠΡΡΠ»Π΅Π΄ΡΠ΅ΠΌΡΠΌΠΈ ΡΡΠ΅Π΄Π°ΠΌΠΈ Π±Π°Π· Π΄Π°Π½Π½ΡΡ ΡΠ²Π»ΡΡΡΡΡ PostgreSQL v11, clickhousedb_fdw ΠΈ Π±Π°Π·Π° Π΄Π°Π½Π½ΡΡ ClickHouse. Π ΠΊΠΎΠ½Π΅ΡΠ½ΠΎΠΌ ΡΡΠ΅ΡΠ΅, ΠΈΠ· PostgreSQL v11 ΠΌΡ Π±ΡΠ΄Π΅ΠΌ Π·Π°ΠΏΡΡΠΊΠ°ΡΡ ΡΠ°Π·Π»ΠΈΡΠ½ΡΠ΅ SQL-Π·Π°ΠΏΡΠΎΡΡ, ΠΌΠ°ΡΡΡΡΡΠΈΠ·ΠΈΡΡΠ΅ΠΌΡΠ΅ ΡΠ΅ΡΠ΅Π· Π½Π°Ρ clickhousedb_fdw Π² Π±Π°Π·Ρ Π΄Π°Π½Π½ΡΡ ClickHouse. ΠΠ°ΡΠ΅ΠΌ ΠΌΡ ΡΠ²ΠΈΠ΄ΠΈΠΌ, ΠΊΠ°ΠΊ ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΡ FDW ΡΡΠ°Π²Π½ΠΈΠ²Π°Π΅ΡΡΡ Ρ ΡΠ΅ΠΌΠΈ ΠΆΠ΅ Π·Π°ΠΏΡΠΎΡΠ°ΠΌΠΈ, Π²ΡΠΏΠΎΠ»Π½ΡΠ΅ΠΌΡΠΌΠΈ Π² Π½Π°ΡΠΈΠ²Π½ΠΎΠΌ PostgreSQL ΠΈ Π½Π°ΡΠΈΠ²Π½ΠΎΠΌ ClickHouse.
ΠΠ°Π·Π° Π΄Π°Π½Π½ΡΡ Clickhouse
ClickHouse β ΡΡΠΎ ΡΠΈΡΡΠ΅ΠΌΠ° ΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΡ Π±Π°Π·Π°ΠΌΠΈ Π΄Π°Π½Π½ΡΡ Π½Π° ΠΎΡΠ½ΠΎΠ²Π΅ ΠΊΠΎΠ»ΠΎΠ½ΠΎΠΊ Ρ ΠΎΡΠΊΡΡΡΡΠΌ ΠΈΡΡ ΠΎΠ΄Π½ΡΠΌ ΠΊΠΎΠ΄ΠΎΠΌ, ΠΊΠΎΡΠΎΡΠ°Ρ ΠΌΠΎΠΆΠ΅Ρ Π΄ΠΎΡΡΠΈΠ³Π°ΡΡ ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΠΈ Π² 100-1000 ΡΠ°Π· Π±ΡΡΡΡΠ΅Π΅, ΡΠ΅ΠΌ ΡΡΠ°Π΄ΠΈΡΠΈΠΎΠ½Π½ΡΠ΅ ΠΏΠΎΠ΄Ρ ΠΎΠ΄Ρ ΠΊ Π±Π°Π·Π°ΠΌ Π΄Π°Π½Π½ΡΡ , ΡΠΏΠΎΡΠΎΠ±Π½Π°Ρ ΠΎΠ±ΡΠ°Π±Π°ΡΡΠ²Π°ΡΡ Π±ΠΎΠ»Π΅Π΅ ΠΌΠΈΠ»Π»ΠΈΠ°ΡΠ΄Π° ΡΡΡΠΎΠΊ ΠΌΠ΅Π½Π΅Π΅ ΡΠ΅ΠΌ Π·Π° ΡΠ΅ΠΊΡΠ½Π΄Ρ.
Clickhousedb_fdw
clickhousedb_fdw β ΠΎΠ±ΠΎΠ»ΠΎΡΠΊΠ° Π²Π½Π΅ΡΠ½ΠΈΡ
Π΄Π°Π½Π½ΡΡ
Π±Π°Π·Ρ Π΄Π°Π½Π½ΡΡ
ClickHouse, ΠΈΠ»ΠΈ FDW, ΡΠ²Π»ΡΠ΅ΡΡΡ ΠΏΡΠΎΠ΅ΠΊΡΠΎΠΌ Ρ ΠΎΡΠΊΡΡΡΡΠΌ ΠΈΡΡ
ΠΎΠ΄Π½ΡΠΌ ΠΊΠΎΠ΄ΠΎΠΌ ΠΎΡ Percona.
ΠΠ°ΠΊ Π²Ρ ΡΠ²ΠΈΠ΄ΠΈΡΠ΅, ΡΡΠΎ ΠΎΠ±Π΅ΡΠΏΠ΅ΡΠΈΠ²Π°Π΅Ρ FDW Π΄Π»Ρ ClickHouse, ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΠΎΠ·Π²ΠΎΠ»ΡΠ΅Ρ SELECT from, ΠΈ INSERT INTO, Π±Π°Π·Ρ Π΄Π°Π½Π½ΡΡ ClickHouse Ρ ΡΠ΅ΡΠ²Π΅ΡΠ° PostgreSQL v11.
FDW ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΈΠ²Π°Π΅Ρ ΡΠ°ΡΡΠΈΡΠ΅Π½Π½ΡΠ΅ ΡΡΠ½ΠΊΡΠΈΠΈ, ΡΠ°ΠΊΠΈΠ΅ ΠΊΠ°ΠΊ aggregate ΠΈ join. ΠΡΠΎ Π·Π½Π°ΡΠΈΡΠ΅Π»ΡΠ½ΠΎ ΠΏΠΎΠ²ΡΡΠ°Π΅Ρ ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΡ Π·Π° ΡΡΠ΅Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΡ ΡΠ΅ΡΡΡΡΠΎΠ² ΡΠ΄Π°Π»Π΅Π½Π½ΠΎΠ³ΠΎ ΡΠ΅ΡΠ²Π΅ΡΠ° Π΄Π»Ρ ΡΡΠΈΡ ΡΠ΅ΡΡΡΡΠΎΠ΅ΠΌΠΊΠΈΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΈΠΉ.
Benchmark environment
- Supermicro server:
- Intel® Xeon® CPU E5-2683 v3 @ 2.00GHz
- 2 sockets / 28 cores / 56 threads
- Memory: 256GB of RAM
- Storage: Samsung SM863 1.9TB Enterprise SSD
- Filesystem: ext4/xfs
- OS: Linux smblade01 4.15.0-42-generic #45~16.04.1-Ubuntu
- PostgreSQL: version 11
Benchmark tests
ΠΠΌΠ΅ΡΡΠΎ ΡΠΎΠ³ΠΎ, ΡΡΠΎΠ±Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΠΊΠ°ΠΊΠΎΠΉ-ΡΠΎ Π½Π°Π±ΠΎΡ Π΄Π°Π½Π½ΡΡ
, ΡΠ³Π΅Π½Π΅ΡΠΈΡΠΎΠ²Π°Π½Π½ΡΠΉ ΠΌΠ°ΡΠΈΠ½ΠΎΠΉ, Π΄Π»Ρ ΡΡΠΎΠ³ΠΎ ΡΠ΅ΡΡΠ°, ΠΌΡ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π»ΠΈ Π΄Π°Π½Π½ΡΠ΅ Β«ΠΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΡ ΠΏΠΎ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ, ΡΠΎΠΎΠ±ΡΠ°Π΅ΠΌΠ°Ρ ΠΎ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ ΡΠ°Π±ΠΎΡΡ ΠΎΠΏΠ΅ΡΠ°ΡΠΎΡΠ°Β» Ρ 1987 ΠΏΠΎ 2018 Π³ΠΎΠ΄. ΠΡ ΠΌΠΎΠΆΠ΅ΡΠ΅ ΠΏΠΎΠ»ΡΡΠΈΡΡ Π΄ΠΎΡΡΡΠΏ ΠΊ Π΄Π°Π½Π½ΡΠΌ
Π Π°Π·ΠΌΠ΅Ρ Π±Π°Π·Ρ Π΄Π°Π½Π½ΡΡ ΡΠΎΡΡΠ°Π²Π»ΡΠ΅Ρ 85 ΠΠ, ΠΎΠ±Π΅ΡΠΏΠ΅ΡΠΈΠ²Π°Ρ ΠΎΠ΄Π½Ρ ΡΠ°Π±Π»ΠΈΡΡ ΠΈΠ· 109 ΡΡΠΎΠ»Π±ΡΠΎΠ².
Benchmark Queries
ΠΠΎΡ Π·Π°ΠΏΡΠΎΡΡ, ΠΊΠΎΡΠΎΡΡΠ΅ Ρ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π» Π΄Π»Ρ ΡΡΠ°Π²Π½Π΅Π½ΠΈΡ ClickHouse, clickhousedb_fdw ΠΈ PostgreSQL.
Q#
Query Contains Aggregates and Group By
Q1
SELECT DayOfWeek, count(*) AS c FROM ontime WHERE Year >= 2000 AND Year <= 2008 GROUP BY DayOfWeek ORDER BY c DESC;
Q2
SELECT DayOfWeek, count(*) AS c FROM ontime WHERE DepDelay>10 AND Year >= 2000 AND Year <= 2008 GROUP BY DayOfWeek ORDER BY c DESC;
Q3
SELECT Origin, count(*) AS c FROM ontime WHERE DepDelay>10 AND Year >= 2000 AND Year <= 2008 GROUP BY Origin ORDER BY c DESC LIMIT 10;
Q4
SELECT Carrier, count() FROM ontime WHERE DepDelay>10 AND Year = 2007 GROUP BY Carrier ORDER BY count() DESC;
Q5
SELECT a.Carrier, c, c2, c1000/c2 as c3 FROM ( SELECT Carrier, count() AS c FROM ontime WHERE DepDelay>10 AND Year=2007 GROUP BY Carrier ) a INNER JOIN ( SELECT Carrier,count(*) AS c2 FROM ontime WHERE Year=2007 GROUP BY Carrier)b on a.Carrier=b.Carrier ORDER BY c3 DESC;
Q6
SELECT a.Carrier, c, c2, c1000/c2 as c3 FROM ( SELECT Carrier, count() AS c FROM ontime WHERE DepDelay>10 AND Year >= 2000 AND Year <= 2008 GROUP BY Carrier) a INNER JOIN ( SELECT Carrier, count(*) AS c2 FROM ontime WHERE Year >= 2000 AND Year <= 2008 GROUP BY Carrier ) b on a.Carrier=b.Carrier ORDER BY c3 DESC;
Q7
SELECT Carrier, avg(DepDelay) * 1000 AS c3 FROM ontime WHERE Year >= 2000 AND Year <= 2008 GROUP BY Carrier;
Q8
SELECT Year, avg(DepDelay) FROM ontime GROUP BY Year;
Q9
select Year, count(*) as c1 from ontime group by Year;
Q10
SELECT avg(cnt) FROM (SELECT Year,Month,count(*) AS cnt FROM ontime WHERE DepDel15=1 GROUP BY Year,Month) a;
Q11
select avg(c1) from (select Year,Month,count(*) as c1 from ontime group by Year,Month) a;
Q12
SELECT OriginCityName, DestCityName, count(*) AS c FROM ontime GROUP BY OriginCityName, DestCityName ORDER BY c DESC LIMIT 10;
Q13
SELECT OriginCityName, count(*) AS c FROM ontime GROUP BY OriginCityName ORDER BY c DESC LIMIT 10;
Query Contains Joins
Q14
SELECT a.Year, c1/c2 FROM ( select Year, count()1000 as c1 from ontime WHERE DepDelay>10 GROUP BY Year) a INNER JOIN (select Year, count(*) as c2 from ontime GROUP BY Year ) b on a.Year=b.Year ORDER BY a.Year;
Q15
SELECT a.βYearβ, c1/c2 FROM ( select βYearβ, count()1000 as c1 FROM fontime WHERE βDepDelayβ>10 GROUP BY βYearβ) a INNER JOIN (select βYearβ, count(*) as c2 FROM fontime GROUP BY βYearβ ) b on a.βYearβ=b.βYearβ;
Table-1: Queries used in benchmark
Query executions
ΠΠΎΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ ΠΊΠ°ΠΆΠ΄ΠΎΠ³ΠΎ ΠΈΠ· Π·Π°ΠΏΡΠΎΡΠΎΠ² ΠΏΡΠΈ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΠΈ Π² ΡΠ°Π·Π½ΡΡ Π½Π°ΡΡΡΠΎΠΉΠΊΠ°Ρ Π±Π°Π·Ρ Π΄Π°Π½Π½ΡΡ : PostgreSQL Ρ ΠΈΠ½Π΄Π΅ΠΊΡΠ°ΠΌΠΈ ΠΈ Π±Π΅Π· Π½ΠΈΡ , ΡΠΎΠ±ΡΡΠ²Π΅Π½Π½ΡΠΉ ClickHouse ΠΈ clickhousedb_fdw. ΠΡΠ΅ΠΌΡ ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°Π΅ΡΡΡ Π² ΠΌΠΈΠ»Π»ΠΈΡΠ΅ΠΊΡΠ½Π΄Π°Ρ .
Q#
PostgreSQL
PostgreSQL (Indexed)
ClickHouse
clickhousedb_fdw
Q1
27920
19634
23
57
Q2
35124
17301
50
80
Q3
34046
15618
67
115
Q4
31632
7667
25
37
Q5
47220
8976
27
60
Q6
58233
24368
55
153
Q7
30566
13256
52
91
Q8
38309
60511
112
179
Q9
20674
37979
31
81
Q10
34990
20102
56
148
Q11
30489
51658
37
155
Q12
39357
33742
186
1333
Q13
29912
30709
101
384
Q14
54126
39913
124
1364212
Q15
97258
30211
245
259
Table-1: Time taken to execute the queries used in benchmark
ΠΡΠΎΡΠΌΠΎΡΡ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΠΎΠ²
ΠΡΠ°ΡΠΈΠΊ ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°Π΅Ρ Π²ΡΠ΅ΠΌΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ Π·Π°ΠΏΡΠΎΡΠ° Π² ΠΌΠΈΠ»Π»ΠΈΡΠ΅ΠΊΡΠ½Π΄Π°Ρ , ΠΎΡΡ X ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°Π΅Ρ Π½ΠΎΠΌΠ΅Ρ Π·Π°ΠΏΡΠΎΡΠ° ΠΈΠ· ΡΠ°Π±Π»ΠΈΡ Π²ΡΡΠ΅, Π° ΠΎΡΡ Y ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°Π΅Ρ Π²ΡΠ΅ΠΌΡ Π²ΡΠΏΠΎΠ»Π½Π΅Π½ΠΈΡ Π² ΠΌΠΈΠ»Π»ΠΈΡΠ΅ΠΊΡΠ½Π΄Π°Ρ . Π Π΅Π·ΡΠ»ΡΡΠ°ΡΡ ClickHouse ΠΈ Π΄Π°Π½Π½ΡΠ΅, ΠΏΠΎΠ»ΡΡΠ΅Π½Π½ΡΠ΅ ΠΈΠ· postgres Ρ ΠΏΠΎΠΌΠΎΡΡΡ clickhousedb_fdw, ΠΏΠΎΠΊΠ°Π·Π°Π½Ρ. ΠΠ· ΡΠ°Π±Π»ΠΈΡΡ Π²ΠΈΠ΄Π½ΠΎ, ΡΡΠΎ ΡΡΡΠ΅ΡΡΠ²ΡΠ΅Ρ ΠΎΠ³ΡΠΎΠΌΠ½Π°Ρ ΡΠ°Π·Π½ΠΈΡΠ° ΠΌΠ΅ΠΆΠ΄Ρ PostgreSQL ΠΈ ClickHouse, Π½ΠΎ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½Π°Ρ ΡΠ°Π·Π½ΠΈΡΠ° ΠΌΠ΅ΠΆΠ΄Ρ ClickHouse ΠΈ clickhousedb_fdw.
ΠΡΠΎΡ Π³ΡΠ°ΡΠΈΠΊ ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°Π΅Ρ ΡΠ°Π·Π½ΠΈΡΡ ΠΌΠ΅ΠΆΠ΄Ρ ClickhouseDB ΠΈ clickhousedb_fdw. Π Π±ΠΎΠ»ΡΡΠΈΠ½ΡΡΠ²Π΅ Π·Π°ΠΏΡΠΎΡΠΎΠ² Π½Π°ΠΊΠ»Π°Π΄Π½ΡΠ΅ ΡΠ°ΡΡ ΠΎΠ΄Ρ FDW Π½Π΅ ΡΠ°ΠΊ Π²Π΅Π»ΠΈΠΊΠΈ ΠΈ Π΅Π΄Π²Π° Π»ΠΈ Π·Π½Π°ΡΠΈΡΠ΅Π»ΡΠ½Ρ, ΠΊΡΠΎΠΌΠ΅ Q12. ΠΡΠΎΡ Π·Π°ΠΏΡΠΎΡ Π²ΠΊΠ»ΡΡΠ°Π΅Ρ Π² ΡΠ΅Π±Ρ ΠΎΠ±ΡΠ΅Π΄ΠΈΠ½Π΅Π½ΠΈΡ ΠΈ ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅ ORDER BY. ΠΠ·-Π·Π° ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΡ ORDER BY GROUP/BY ΠΈ ORDER BY Π½Π΅ ΠΎΠΏΡΡΠΊΠ°ΡΡΡΡ Π΄ΠΎ ClickHouse.
Π ΡΠ°Π±Π»ΠΈΡΠ΅ 2 ΠΌΡ Π²ΠΈΠ΄ΠΈΠΌ ΡΠΊΠ°ΡΠΎΠΊ Π²ΡΠ΅ΠΌΠ΅Π½ΠΈ Π² Π·Π°ΠΏΡΠΎΡΠ°Ρ Q12 ΠΈ Q13. ΠΠΎΠ²ΡΠΎΡΡΡΡ, ΡΡΠΎ Π²ΡΠ·Π²Π°Π½ΠΎ ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅ΠΌ ORDER BY. Π§ΡΠΎΠ±Ρ ΠΏΠΎΠ΄ΡΠ²Π΅ΡΠ΄ΠΈΡΡ ΡΡΠΎ, Ρ Π²ΡΠΏΠΎΠ»Π½ΠΈΠ» Π·Π°ΠΏΡΠΎΡΡ Q-14 ΠΈ Q-15 Ρ ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅ΠΌ ORDER BY ΠΈ Π±Π΅Π· Π½Π΅Π³ΠΎ. ΠΠ΅Π· ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΡ ORDER BY Π²ΡΠ΅ΠΌΡ Π·Π°Π²Π΅ΡΡΠ΅Π½ΠΈΡ ΡΠΎΡΡΠ°Π²Π»ΡΠ΅Ρ 259 ΠΌΡ, Π° Ρ ΠΏΡΠ΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅ΠΌ ORDER BY β 1364212. ΠΠ»Ρ ΠΎΡΠ»Π°Π΄ΠΊΠΈ ΡΡΠΎΠ³ΠΎ Π·Π°ΠΏΡΠΎΡΠ° Ρ ΠΎΠ±ΡΡΡΠ½ΡΡ ΠΎΠ±Π° Π·Π°ΠΏΡΠΎΡΠ°, Π° Π·Π΄Π΅ΡΡ ΠΏΡΠΈΠ²Π΅Π΄Π΅Π½Ρ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ ΠΎΠ±ΡΡΡΠ½Π΅Π½ΠΈΡ.
Q15: Without ORDER BY Clause
bm=# EXPLAIN VERBOSE SELECT a."Year", c1/c2
FROM (SELECT "Year", count(*)*1000 AS c1 FROM fontime WHERE "DepDelay" > 10 GROUP BY "Year") a
INNER JOIN(SELECT "Year", count(*) AS c2 FROM fontime GROUP BY "Year") b ON a."Year"=b."Year";
Q15: Query Without ORDER BY Clause
QUERY PLAN
Hash Join (cost=2250.00..128516.06 rows=50000000 width=12)
Output: fontime."Year", (((count(*) * 1000)) / b.c2)
Inner Unique: true Hash Cond: (fontime."Year" = b."Year")
-> Foreign Scan (cost=1.00..-1.00 rows=100000 width=12)
Output: fontime."Year", ((count(*) * 1000))
Relations: Aggregate on (fontime)
Remote SQL: SELECT "Year", (count(*) * 1000) FROM "default".ontime WHERE (("DepDelay" > 10)) GROUP BY "Year"
-> Hash (cost=999.00..999.00 rows=100000 width=12)
Output: b.c2, b."Year"
-> Subquery Scan on b (cost=1.00..999.00 rows=100000 width=12)
Output: b.c2, b."Year"
-> Foreign Scan (cost=1.00..-1.00 rows=100000 width=12)
Output: fontime_1."Year", (count(*))
Relations: Aggregate on (fontime)
Remote SQL: SELECT "Year", count(*) FROM "default".ontime GROUP BY "Year"(16 rows)
Q14: Query With ORDER BY Clause
bm=# EXPLAIN VERBOSE SELECT a."Year", c1/c2 FROM(SELECT "Year", count(*)*1000 AS c1 FROM fontime WHERE "DepDelay" > 10 GROUP BY "Year") a
INNER JOIN(SELECT "Year", count(*) as c2 FROM fontime GROUP BY "Year") b ON a."Year"= b."Year"
ORDER BY a."Year";
Q14: Query Plan with ORDER BY Clause
QUERY PLAN
Merge JoinΒ (cost=2.00..628498.02 rows=50000000 width=12)Β Β
Output: fontime."Year", (((count(*) * 1000)) / (count(*)))Β Β
Inner Unique: trueΒ Β Merge Cond: (fontime."Year" = fontime_1."Year")Β Β
->Β GroupAggregateΒ (cost=1.00..499.01 rows=1 width=12)Β Β Β Β
Output: fontime."Year", (count(*) * 1000)Β Β Β Β Β
Group Key: fontime."Year"Β Β Β Β Β
->Β Foreign Scan on public.fontimeΒ (cost=1.00..-1.00 rows=100000 width=4)Β Β Β Β Β Β Β Β
Remote SQL: SELECT "Year" FROM "default".ontime WHERE (("DepDelay" > 10))
ORDER BY "Year" ASCΒ Β
->Β GroupAggregateΒ (cost=1.00..499.01 rows=1 width=12)Β Β Β Β Β
Output: fontime_1."Year", count(*)Β Β Β Β Β Group Key: fontime_1."Year"Β Β Β Β Β
->Β Foreign Scan on public.fontime fontime_1Β (cost=1.00..-1.00 rows=100000 width=4)Β
Β Β Β Β Β Β Β
Remote SQL: SELECT "Year" FROM "default".ontime ORDER BY "Year" ASC(16 rows)
ΠΡΠ²ΠΎΠ΄
Π Π΅Π·ΡΠ»ΡΡΠ°ΡΡ ΡΡΠΈΡ ΡΠΊΡΠΏΠ΅ΡΠΈΠΌΠ΅Π½ΡΠΎΠ² ΠΏΠΎΠΊΠ°Π·ΡΠ²Π°ΡΡ, ΡΡΠΎ ClickHouse ΠΏΡΠ΅Π΄Π»Π°Π³Π°Π΅Ρ Π΄Π΅ΠΉΡΡΠ²ΠΈΡΠ΅Π»ΡΠ½ΠΎ Ρ ΠΎΡΠΎΡΡΡ ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΡ, Π° clickhousedb_fdw ΠΏΡΠ΅Π΄Π»Π°Π³Π°Π΅Ρ ΠΏΡΠ΅ΠΈΠΌΡΡΠ΅ΡΡΠ²Π° ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΠΈ ClickHouse ΠΈΠ· PostgreSQL. Π₯ΠΎΡΡ ΠΏΡΠΈ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°Π½ΠΈΠΈ clickhousedb_fdw Π΅ΡΡΡ Π½Π΅ΠΊΠΎΡΠΎΡΡΠ΅ Π½Π°ΠΊΠ»Π°Π΄Π½ΡΠ΅ ΡΠ°ΡΡ ΠΎΠ΄Ρ, ΠΎΠ½ΠΈ Π½Π΅Π·Π½Π°ΡΠΈΡΠ΅Π»ΡΠ½Ρ ΠΈ ΡΠΎΠΏΠΎΡΡΠ°Π²ΠΈΠΌΡ Ρ ΠΏΡΠΎΠΈΠ·Π²ΠΎΠ΄ΠΈΡΠ΅Π»ΡΠ½ΠΎΡΡΡΡ, Π΄ΠΎΡΡΠΈΠ³Π½ΡΡΠΎΠΉ ΠΏΡΠΈ Π΅ΡΡΠ΅ΡΡΠ²Π΅Π½Π½ΠΎΠΌ Π·Π°ΠΏΡΡΠΊΠ΅ Π² Π±Π°Π·Π΅ Π΄Π°Π½Π½ΡΡ ClickHouse. ΠΡΠΎ ΡΠ°ΠΊΠΆΠ΅ ΠΏΠΎΠ΄ΡΠ²Π΅ΡΠΆΠ΄Π°Π΅Ρ, ΡΡΠΎ fdw Π² PostgreSQL ΠΎΠ±Π΅ΡΠΏΠ΅ΡΠΈΠ²Π°Π΅Ρ Π·Π°ΠΌΠ΅ΡΠ°ΡΠ΅Π»ΡΠ½ΡΠ΅ ΡΠ΅Π·ΡΠ»ΡΡΠ°ΡΡ.
Π’Π΅Π»Π΅Π³ΡΠ°ΠΌ ΡΠ°Ρ ΠΏΠΎ Clickhouse
Π’Π΅Π»Π΅Π³ΡΠ°ΠΌ ΡΠ°Ρ ΠΏΠΎ PostgreSQL
ΠΡΡΠΎΡΠ½ΠΈΠΊ: habr.com