This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-28
Channels
- # aleph (7)
- # babashka (13)
- # beginners (10)
- # biff (4)
- # calva (75)
- # cljs-dev (22)
- # clojure (55)
- # clojure-berlin (1)
- # clojure-europe (15)
- # clojure-nl (1)
- # clojure-norway (35)
- # clojure-serbia (1)
- # clojure-uk (2)
- # clojurescript (46)
- # community-development (1)
- # core-async (23)
- # data-science (1)
- # datalevin (2)
- # datascript (10)
- # datomic (11)
- # fulcro (28)
- # helix (12)
- # hyperfiddle (26)
- # introduce-yourself (4)
- # malli (16)
- # off-topic (1)
- # pathom (4)
- # pedestal (1)
- # polylith (12)
- # quil (11)
- # releases (3)
- # scittle (24)
- # shadow-cljs (85)
- # specter (1)
- # sql (9)
- # xtdb (5)
I'm having a SQL issue at work. I made a SO post about it - sharing in case anyone knows off the top of their head https://stackoverflow.com/questions/78239454/what-is-the-proper-way-to-index-status-history-tables
👀 1
Taking a shot here from the hip:
CREATE
OR REPLACE VIEW current_apple_quality AS
select *
from (
SELECT
apple_quality.apple_id,
apple_quality.id,
apple_quality.created_at,
apple_quality.updated_at,
apple_quality.quality,
apple_quality.apple_id,
apple_quality.valid_at,
row_number() over(
partition by apple_quality.apple_id
order by apple_quality.valid_at desc
) as rn
FROM apple_quality
) t
where t.rn = 1
probably unhelpful given your current schema, but I like the way https://github.com/xocolatl/periods does it: you treat the main table as if it were mutable, the history is kept in a separate table
Have you tried a lateral join or EXISTS subquery? That might nudge the query planner towards more of a nested loop than a scan then join. Also worth making sure your statistics are up to date first.