Skip to content

Instantly share code, notes, and snippets.

@bahrmichael
Created October 30, 2020 14:21
Show Gist options
  • Save bahrmichael/aac9d0e5665e089af7ffc0eafdb3ead7 to your computer and use it in GitHub Desktop.
Save bahrmichael/aac9d0e5665e089af7ffc0eafdb3ead7 to your computer and use it in GitHub Desktop.
Query type: nested with inner join
Duration: 3s
Returned entries: 3
Query:
SELECT
snapshots.type_id, snapshots.measure_value::double
FROM
(SELECT
a.type_id, MAX(a.time) AS created_at
FROM
"MarketWatch"."Snapshots" a
WHERE a.measure_name = 'volume'
AND a.buy = 'False'
AND a.time >= ago(48h)
AND a.location_id = '60003760'
AND a.type_id in ('5599','9734','438')
GROUP BY a.type_id
)
AS latest
INNER JOIN
"MarketWatch"."Snapshots" snapshots
ON snapshots.type_id = latest.type_id
AND snapshots.time = latest.created_at
AND snapshots.buy = 'False'
WHERE snapshots.measure_name = 'volume'
AND snapshots.buy = 'False'
---
Query type: Flat query
Duration: 2s
Returned entries: 3
Query:
SELECT min(measure_value::double) as volume, type_id, BIN(time, 1d) as day FROM "MarketWatch"."Snapshots"
WHERE measure_name = 'volume'
AND location_id = '60003760'
AND type_id in ('20', '34')
AND buy = 'False'
AND time >= ago(6h)
GROUP BY type_id, BIN(time, 1d)
ORDER BY day DESC
---
Query type: Simple, but with lots of data returned
Duration: 5.5s
Returned entries: 1000+
Query:
SELECT min(measure_value::double) as volume, type_id, BIN(time, 1d) as day FROM "MarketWatch"."Snapshots"
WHERE measure_name = 'volume'
AND location_id = '60003760'
AND buy = 'False'
AND time >= ago(6h)
GROUP BY type_id, BIN(time, 1d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment