Re: Last event per user

From: Michael Lewis <mlewis(at)entrata(dot)com>
To: Luís Roberto Weck <luisroberto(at)siscobra(dot)com(dot)br>
Cc: "pgsql-performance(at)lists(dot)postgresql(dot)org" <pgsql-performance(at)lists(dot)postgresql(dot)org>
Subject: Re: Last event per user
Date: 2019-08-12 21:56:31
Message-ID: CAHOFxGqhh5T2Uidw6ha404kiX87ipgs4MCGKOoDOqsp=j4Z89g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message David Rowley 2019-08-12 22:25:23 Re: Planner performance in partitions
Previous Message Luís Roberto Weck 2019-08-12 20:57:46 Last event per user