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 |
Subject: | Re: Last event per user |
Date: | 2019-08-12 23:09:53 |
Message-ID: | CAHOFxGpiuT2Hy+5DgX+G67tMcecuNgZZ5KBT69qG0MPFJ-CUYw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-performance |
On Mon, Aug 12, 2019 at 5:03 PM Luís Roberto Weck <
luisroberto(at)siscobra(dot)com(dot)br> wrote:
> If you modify last_user_event_2 to select user and event info in the view,
> and just put there where clause directly on the view which is not joined to
> anything, instead of on the "extra copy" of the users table like you were
> showing previously, I would expect that the performance should be excellent.
>
> But I need user_id and user_group to be outside of the view definition.
> user_id and user_group are dynamic values, as in, I need to call this query
> multiple times for different user_ids and user_groups .
>
I don't follow. Perhaps there is something within the limitations of the
ORM layer that I am not expecting. If you have this view-
"last_user_event_2"
SELECT u.*, e.*
FROM users u
JOIN LATERAL (SELECT *
FROM events
WHERE user_id = u.user_id
AND user_group = u.user_group
ORDER BY timestamp_inc DESC
LIMIT 1 ) e ON TRUE
And you execute a query like this-
SELECT * FROM last_user_event_2 e WHERE user_id = 1272897 and user_group =
19117;
Then I would expect very good performance.
From | Date | Subject | |
---|---|---|---|
Next Message | Piotr Włodarczyk | 2019-08-13 06:29:06 | ODP: Planner performance in partitions |
Previous Message | Luís Roberto Weck | 2019-08-12 23:03:54 | Re: Last event per user |