The query plans are different, is one better than the other?
QUERY PLAN
-----------------------------------------------------------------------------------------------
Sort (cost=27.96..28.01 rows=19 width=37)
Sort Key: a.username, a.ts
-> Seq Scan on switches a (cost=0.00..27.55 rows=19 width=37)
Filter: (task IS NOT NULL)
SubPlan 1
-> Limit (cost=1.38..1.38 rows=1 width=8)
-> Sort (cost=1.38..1.39 rows=4 width=8)
Sort Key: switches.ts
-> Seq Scan on switches (cost=0.00..1.36 rows=4 width=8)
Filter: ((ts > a.ts) AND ((username)::text = (a.username)::text))
(10 rows)
QUERY PLAN
-----------------------------------------------------------------------------------------------------------
Sort (cost=28.34..28.39 rows=19 width=45)
Sort Key: switches.username, switches.ts
-> Nested Loop Left Join (cost=1.38..27.93 rows=19 width=45)
-> Seq Scan on switches (cost=0.00..1.24 rows=19 width=37)
Filter: (task IS NOT NULL)
-> Limit (cost=1.38..1.38 rows=1 width=8)
-> Sort (cost=1.38..1.39 rows=4 width=8)
Sort Key: switches_1.ts
-> Seq Scan on switches switches_1 (cost=0.00..1.36 rows=4 width=8)
Filter: ((ts > switches.ts) AND ((username)::text = (switches.username)::text))
(10 rows)