walkable-server / walkable

A Clojure(script) SQL library for building APIs: Datomic® (GraphQL-ish) pull syntax, data driven configuration, dynamic filtering with relations in mind
https://walkable.gitlab.io/
Eclipse Public License 2.0
444 stars 15 forks source link

change generated sql to improve performance #137

Closed myguidingstar closed 5 years ago

myguidingstar commented 5 years ago

eg make use of with for subselects in N+1 queries

myguidingstar commented 5 years ago

replace currently generated queries like:

(SELECT ("cow"."color") AS "cow/color", ("cow"."index") AS "cow/index" FROM "cow" WHERE (("cow"."index")=(10)) LIMIT 5)
  UNION ALL
(SELECT ("cow"."color") AS "cow/color", ("cow"."index") AS "cow/index" FROM "cow" WHERE (("cow"."index")=(20)) LIMIT 5)

with:

WITH walkable_common_join AS (
SELECT ("cow"."color") AS "cow/color", ("cow"."index") AS "cow/index" FROM "cow"
)
  (SELECT * FROM walkable_common_join WHERE (("cow/index")=(10)) LIMIT 5)
  UNION ALL
  (SELECT * FROM walkable_common_join WHERE (("cow/index")=(20)) LIMIT 5)
myguidingstar commented 5 years ago

The use of CTEs should be optional, or even configurable for each join keyword because: