# SQL vs Ecto optimization/translation help

**URL:** <https://forum.elixirforum.com/t/sql-vs-ecto-optimization-translation-help/5559>\
**Category:** Questions\
**Tags:** ecto, sql\
**Created:** [May 29, 2017, 4:58am UTC](https://forum.elixirforum.com/t/sql-vs-ecto-optimization-translation-help/5559 "2017-05-29T04:58:41Z")\
**Posts on this page:** 1\
**Showing post:** 13

<div class="post-metadata">

**Author:** ![bglusman](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/bglusman/32/9459_2.png) [@bglusman](https://forum.elixirforum.com/u/bglusman)\
**Post date:** [May 30, 2017, 7:41pm UTC](https://forum.elixirforum.com/t/sql-vs-ecto-optimization-translation-help/5559/13 "2017-05-30T19:41:27Z")

</div>

Possibly? I’m unclear how or what ordering would really matter for here, I think of order\_by for sorting and though I sort at the end by credit\_type name, that part is trivial because there’s generally only 3 credit types…

What I really want, ideally, is to get Ecto to return the CreditType structs with stocks preloaded, which it does now, but in the process it pulls all foods from the DB which is inefficient… it just seems like there’s no good way to preload stocks without also preloading all the joining schemas/models along the way.. I do also need the foods from those stocks, but not foods that are “dead ends” and do not lead to any stocks for the particular facility id provided.

---

_[View the full topic](https://forum.elixirforum.com/t/sql-vs-ecto-optimization-translation-help/5559)._
