Skip to content

Instantly share code, notes, and snippets.

@bcambel
Last active December 10, 2015 16:36
Show Gist options
  • Select an option

  • Save bcambel/e752f0345026e2fd38fe to your computer and use it in GitHub Desktop.

Select an option

Save bcambel/e752f0345026e2fd38fe to your computer and use it in GitHub Desktop.
explain analyse
select sum(pv), country FROM (
select sum(pv) as pv, country
from events_2015_09_01
group by country
UNION ALL
select sum(pv) as pv, country
from events_2015_09_02
group by country
UNION ALL
select sum(pv) as pv, country
from events_2015_09_03
group by country
) AS merged_days
group by country
order by sum(pv) desc;
Sort (cost=510008.93..510009.43 rows=200 width=17) (actual time=9256.076..9256.085 rows=216 loops=1)
Sort Key: (sum("*SELECT* 1".pv)) DESC
Sort Method: quicksort Memory: 36kB
-> HashAggregate (cost=509998.78..510001.28 rows=200 width=17) (actual time=9255.889..9255.954 rows=216 loops=1)
Group Key: "*SELECT* 1".country
-> Append (cost=18582.28..509986.38 rows=2481 width=17) (actual time=320.171..9253.958 rows=4252 loops=1)
-> Subquery Scan on "*SELECT* 1" (cost=18582.28..18583.86 rows=79 width=16) (actual time=320.169..320.221 rows=144 loops=1)
-> HashAggregate (cost=18582.28..18583.07 rows=79 width=12) (actual time=320.168..320.196 rows=144 loops=1)
Group Key: events_2015_09_01.country
-> Seq Scan on events_2015_09_01 (cost=0.00..16098.52 rows=496752 width=12) (actual time=0.012..68.434 rows=496752 loops=1)
-> Subquery Scan on "*SELECT* 2" (cost=17897.01..17898.67 rows=83 width=16) (actual time=324.356..324.420 rows=144 loops=1)
-> HashAggregate (cost=17897.01..17897.84 rows=83 width=12) (actual time=324.353..324.392 rows=144 loops=1)
Group Key: events_2015_09_02.country
-> Seq Scan on events_2015_09_02 (cost=0.00..15500.67 rows=479267 width=12) (actual time=0.026..85.460 rows=479267 loops=1)
-> Subquery Scan on "*SELECT* 3" (cost=17721.11..17722.83 rows=86 width=16) (actual time=315.809..315.873 rows=144 loops=1)
-> HashAggregate (cost=17721.11..17721.97 rows=86 width=12) (actual time=315.808..315.854 rows=144 loops=1)
Group Key: events_2015_09_03.country
-> Seq Scan on events_2015_09_03 (cost=0.00..15356.74 rows=472874 width=12) (actual time=0.010..84.895 rows=472874 loops=1)
-> Subquery Scan on "*SELECT* 4" (cost=15982.97..15984.49 rows=76 width=17) (actual time=289.241..289.293 rows=137 loops=1)
-> HashAggregate (cost=15982.97..15983.73 rows=76 width=13) (actual time=289.239..289.277 rows=137 loops=1)
Group Key: events_2015_09_04.country
-> Seq Scan on events_2015_09_04 (cost=0.00..13846.98 rows=427198 width=13) (actual time=0.011..77.566 rows=427198 loops=1)
-> Subquery Scan on "*SELECT* 5" (cost=15006.29..15007.95 rows=83 width=17) (actual time=272.963..273.016 rows=139 loops=1)
-> HashAggregate (cost=15006.29..15007.12 rows=83 width=13) (actual time=272.961..272.999 rows=139 loops=1)
Group Key: events_2015_09_05.country
-> Seq Scan on events_2015_09_05 (cost=0.00..13006.86 rows=399886 width=13) (actual time=0.011..73.353 rows=399886 loops=1)
-> Subquery Scan on "*SELECT* 29" (cost=18205.22..18207.00 rows=89 width=16) (actual time=332.204..332.274 rows=150 loops=1)
-> HashAggregate (cost=18205.22..18206.11 rows=89 width=12) (actual time=332.203..332.251 rows=150 loops=1)
Group Key: events_2015_09_30.country
-> Seq Scan on events_2015_09_30 (cost=0.00..15759.15 rows=489215 width=12) (actual time=0.014..91.622 rows=489215 loops=1)
Planning time: 0.929 ms
Execution time: 9256.820 ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment