开发者

Fewer codes but with many database queries or many codes but with fewer database queries? [closed]

开发者_如何学GoIt's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

There are two options I want to take one of them:

  1. Writing fewer codes but with many database queries.
  2. Writing many codes but with fewer database queries.

Dependence on the database in everything, or if you found ways but not the best to make you avoid using the database. Which one do you prefer?


Use as few queries as possible, to execute queries your script needs to contact the SQL server every time which is much slower than the execution of code.


Always go for the less database queries - it reduces load, and it's faster. Of course, there are exceptions to this rule (I can't think of any, though). In general, try to use as few database calls as possible by utilising JOINs, etcetera.


Few simple queries is better than 1 difficult query. Sometimes few simple queries can be united to 1 simple query - it's normal. But very often I see strange queries with 5-10 JOINS and sub-selects, and only reason - BECAUSE I CAN DO THIS IN ONE QUERY!!1!.

Also, results of simple queries often can be cached, so all you need is fetch rest of simple queries. Not all results can be cached, so difficult queries looses here.

Also, I don't like JOINs (because JOIN = SLOW QUERY very often).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜