Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It depends on a lot of factors - but most crucially:</p> <ul> <li>complexity of calculations (prefer doing complex crunching on an app-server, since that scales <em>out</em>; rather than a db server, which scales <em>up</em>)</li> <li>volume of data (if you need to access/aggregate a lot of data, doing it at the db server will save bandwidth, and disk io if the aggregates can be done inside indexes)</li> <li>convenience (sql is not the best language for complex work - especially not great for procedural work, but very good for set-based work; lousy error-handling, though)</li> </ul> <p>As always, if you <em>do</em> bring the data back to the app-server, minimising the columns and rows will be to your advantage. Making sure the query is tuned and appropriately indexed will help either scenario.</p> <p>Re your note:</p> <blockquote> <p>and then loop through the records </p> </blockquote> <p><em>Looping</em> through records is almost always the wrong thing to do in sql - writing a set-based operation is preferred.</p> <p><em>As a general rule</em>, I prefer to keep the database's job to a minimum "store this data, fetch this data" - however, there are always examples of scenarios where an elegant query at the server can save a lot of bandwidth.</p> <p>Also consider: if this is computationally expensive, can it be cached somewhere?</p> <p>If you want an <em>accurate</em> "which is better"; code it both ways and compare it (noting that a first draft of either is likely not 100% tuned). But factor in typical usage to that: if, in reality, it is being called 5 times (separately) at once, then simulate that: don't compare just a single "1 of these vs 1 of those".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload