Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link

I somehow acquired the idea that I should reduce the number of trips to the database as much as possible and so I use a lot of very long queries.

This basically says, that you are worried about response time of database. This matters when the database is not on the same machine as your application, but your application is for example in USA and your database is in Australia. In this case it might be (but does not have to be) better to use one complex query instead of a couple of simple queries.

Optimization of your queries should be done in that way that you actually measure time the queries take to execute. There is no golden rule like: "putting all simple queries into one complex query is always better". The result of such "rule" can be:

  • overly complex query
  • slow query
  • queries which are hard to maintain
  • queries which are hard to understand by other developers

Janos mentioned a good point with using SELECT col1, col2, ..., you can find more in depth information about it here: Why is SELECT * considered harmful? Why is SELECT * considered harmful?

I somehow acquired the idea that I should reduce the number of trips to the database as much as possible and so I use a lot of very long queries.

This basically says, that you are worried about response time of database. This matters when the database is not on the same machine as your application, but your application is for example in USA and your database is in Australia. In this case it might be (but does not have to be) better to use one complex query instead of a couple of simple queries.

Optimization of your queries should be done in that way that you actually measure time the queries take to execute. There is no golden rule like: "putting all simple queries into one complex query is always better". The result of such "rule" can be:

  • overly complex query
  • slow query
  • queries which are hard to maintain
  • queries which are hard to understand by other developers

Janos mentioned a good point with using SELECT col1, col2, ..., you can find more in depth information about it here: Why is SELECT * considered harmful?

I somehow acquired the idea that I should reduce the number of trips to the database as much as possible and so I use a lot of very long queries.

This basically says, that you are worried about response time of database. This matters when the database is not on the same machine as your application, but your application is for example in USA and your database is in Australia. In this case it might be (but does not have to be) better to use one complex query instead of a couple of simple queries.

Optimization of your queries should be done in that way that you actually measure time the queries take to execute. There is no golden rule like: "putting all simple queries into one complex query is always better". The result of such "rule" can be:

  • overly complex query
  • slow query
  • queries which are hard to maintain
  • queries which are hard to understand by other developers

Janos mentioned a good point with using SELECT col1, col2, ..., you can find more in depth information about it here: Why is SELECT * considered harmful?

Source Link
user40964
user40964

I somehow acquired the idea that I should reduce the number of trips to the database as much as possible and so I use a lot of very long queries.

This basically says, that you are worried about response time of database. This matters when the database is not on the same machine as your application, but your application is for example in USA and your database is in Australia. In this case it might be (but does not have to be) better to use one complex query instead of a couple of simple queries.

Optimization of your queries should be done in that way that you actually measure time the queries take to execute. There is no golden rule like: "putting all simple queries into one complex query is always better". The result of such "rule" can be:

  • overly complex query
  • slow query
  • queries which are hard to maintain
  • queries which are hard to understand by other developers

Janos mentioned a good point with using SELECT col1, col2, ..., you can find more in depth information about it here: Why is SELECT * considered harmful?

lang-sql

AltStyle によって変換されたページ (->オリジナル) /