Re: Last event per user - Mailing list pgsql-performance

From Michael Lewis
Subject Re: Last event per user
Date
Msg-id CAHOFxGqhh5T2Uidw6ha404kiX87ipgs4MCGKOoDOqsp=j4Z89g@mail.gmail.com
Whole thread Raw
In response to Last event per user  (Luís Roberto Weck <luisroberto@siscobra.com.br>)
Responses Re: Last event per user  (Luís Roberto Weck <luisroberto@siscobra.com.br>)
List pgsql-performance
The obfuscation makes it difficult to guess at the query you are writing and the schema you are using. Can you provide any additional information without revealing sensitive info?

1) Do you have an index on ( user_id ASC, timestamp_inc DESC ) ?
2) Sub-queries can't be re-written inline by the optimizer when there is an aggregate inside the subquery, and I think DISTINCT ON would behave the same. So, that might explain the significant change in behavior when the lateral is used. I am guessing at how you wrote the two versions of the view though.

Obviously not best design, but you could insert events as "is_latest" and update any prior events for that user via trigger as is_latest = false.

pgsql-performance by date:

Previous
From: Luís Roberto Weck
Date:
Subject: Last event per user
Next
From: David Rowley
Date:
Subject: Re: Planner performance in partitions