> If anyone wants to take this further, maybe this is a good place to start.
I should have re-stated the reason for my original post.
Exactly the same query, on exactly the same data, takes 1.8 seconds on Sql Server, 1.0 seconds on SQLite3, and 1607 seconds, or 26 minutes, on PostgreSQL 9.4.4.