Fork me on GitHub
#clojure-europe
<
2023-03-22
>
ray08:03:54

Good morning (from last night)

👏 4
❤️ 2
ray12:03:45

I was hoping for a big red fireball under those clouds but I'll take what I can get

Benjamin08:03:00

:mate_drink: 👋

2
reefersleep08:03:06

Good morning

dharrigan09:03:29

Good Morning

schmalz09:03:47

Morning all ☀️ .

thomas12:03:19

I'm learning way too much about Postgres triggers and functions then I want to know...

mccraigmccraig12:03:42

what's the use-case @U052852ES ?

reefersleep12:03:43

At least Postgres is very widely used, so more Postgres details will very often be good for your resumé 🙂 Ignoring that you forgot about the details later on 😄

thomas12:03:45

The system I'm working on has about 3.5K triggers and are interconnected in various ways.

😱 2
thomas12:03:41

and I have to add/change triggers so that we can take part of the compute problem they are currently doing in recursive SQL queries in an external Rust process.

2
mccraigmccraig12:03:50

😱 @ 3.5K triggers - i hope they have been very disciplined about controlling and documenting interactions!

thomas12:03:29

I don't know what that is?

thomas12:03:58

but yes, spaghetti code would be a kind description of this system. Large parts of the business logic is in SQL.

mccraigmccraig12:03:09

as in that's an awful lot of triggers - and triggers can presumably trip other triggers, which sounds like a recipe for a difficult to understand system

thomas12:03:27

and just updating the triggers takes about 20 minutes on a large system.

mccraigmccraig12:03:43

why did they choose to use SQL to implement business logic @U052852ES?

thomas12:03:20

No idea... this happened years ago and then it just grew larger and larger.

mccraigmccraig12:03:46

a grey-goo system!

thomas12:03:24

yup, thousand of lines of SQL. Love it!

ray14:03:42

declarative and functional trollface

slipset16:03:13

I’m learning that where (foo = ANY($1)) or (bar = ANY($2)) is really slow given large $1 and $2

slipset16:03:40

even with indexes on foo and bar

mccraigmccraig16:03:57

are $1 and $2 sub-queries @U04V5VAUN?

slipset16:03:14

No, they’re arrays

slipset16:03:58

We’re migrating from mongo to postgres, so we have a ton of clojurespace joins

mccraigmccraig16:03:27

how big are $1 and $2 ?

slipset16:03:07

can be tens of thousands…

mccraigmccraig16:03:04

ok, so not massive... i woulda thought that could have been optimised like a hash join... i.e. index scan with hash-tables from $1 and $2

mccraigmccraig16:03:38

does it get quicker if you put $1 and $2 into temp tables and do an explicit join ?

slipset16:03:50

haven’t tried that.

reefersleep16:03:41

In my (very limited!) experience, handling arrays just leads to wishing you'd done a relational table instead.

reefersleep16:03:51

The only advantage that I know of with arrays is that when fetching data, you don't have to do an explicit join to get the equivalent of an array via tables. But you lose out on a bunch of readily available and better understood table-oriented SQL.

reefersleep16:03:36

Always ready to get schooled, though 🤓 hope you figure out your problem, @U04V5VAUN

slipset16:03:25

Yah, a join would have been a lot better, but it’s not possible atm 😕

thomas09:03:00

@U04V5V0V4 but it isn't composable!

ray09:03:04

iirc a sql function can be named and can call others, so why not?

thomas09:03:01

yes, functions can call each other. But in my experience you can't (or it is difficult) to just combine code and glue it together. ymmv of course

reefersleep09:03:46

Can you write tests for SQL functions? :thinking_face:

thomas10:03:45

not that I am aware of? But who know?

mccraigmccraig10:03:44

i guess the difficulty with composing sql fns is managing side-effects - they are mostly not very pure

ray10:03:00

kinda depends on whether they are contained within the same transaction ie is the shared mutable state updated consistently?

ray10:03:33

but yes, in practise it's usually a sht1sh0w cos nobody cares about this stuff 🙂

thomas10:03:05

yup, and the developer experience kinda sucks IMHO.

2
ordnungswidrig15:03:29

Boã tarde.

🤯 4