Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cardinality :many in MS SQL: replace array_agg with Clojure fn #17

Closed
wants to merge 3 commits into from

Conversation

danskarda
Copy link
Collaborator

to-many-join-column-query uses GROUP BY and array_agg aggregate function. Unfortunately not all SQL databases implement it, SQL Server is one of them (#15).

I propose to move this functionality out of SQL to Clojure function. Return all relations and group them in Clojure code. This makes it less dependent on specific SQL implementations. One drawback could be performance (it transfers more data) but I estimate the impact will be minimal. I guess performance is not main fulcro-rad-sql concern and its performance can be tuned elsewhere (roundtrips, formattign sqls with ids).

I considered also solution with string_agg, which strangely is implemented in MS SQL. But I decided against as primary keys can have different types and this could lead to mess.

MS SQL does not support arrays. This patch removes array_agg and moves
aggregation into Clojure code.
Imagine you have Account and Address one-to-many relation. You filter on
Account.ID and left-join Address to Account. Then not-only you filter by
Address.AccountId but moreover Account must exist.

Now is LEFT JOIN necessary? It would return result [Account.ID, NULL] if no
Address exist. But these results are filtered out in later stages of query
post-processing, because when there is no Address, adapter will return
{::account/id ID} and not {::account/id ID, ::account/addresses []}.

LEFT JOIN is not necessary.
@awkay
Copy link
Member

awkay commented Dec 10, 2022

Does this test out against the other databases? Seems like a perfectly good idea to me, and I'm willing to merge it. I don't use this adapter, so it won't get much testing from me.

@awkay
Copy link
Member

awkay commented Dec 13, 2022

If you'll squash this and confirm it is tested, I'll merge and release it.

@awkay awkay deleted the branch fulcrologic:develop December 30, 2022 16:54
@awkay awkay closed this Dec 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants