MySQL queries - how expensive are they really?
I've heard that mysql queries are very expensive, and that you should avoid at all costs making too many of them.
I'm developing a site that will be used by quite a few people, and I'm wondering:
How expensive are mysql queries actually? If I have 400,000 people in my database, how expensive is it to query it for one of them?
How close attention do I need to pay that I don't make too many queries per client requ开发者_运维技巧est?
Edit: TomTom couldn't be more correct with his answer. According to perormance tests on the sites linked to in the comments (and a couple sites I found through a "mysql queries per second" search), I won't be encountering problems for quite a while - mysql can do thousands of queries per second with a remote server.
Just ignore it. Seriously. If you need data, you need data. Make sure your queries are reasonable fast (i.e. proper indices). Get a proper server for handling the load. Use output caching as makes sense, start caching data once you know where you actually HAVE a problem.
As long as your queries are precise and written as efficient as possible, mySQL is made to be able to perform these actions.
If you say have 400,000 users though, and your noticing performance issues you should be making enough money off of these users to upgrade your server anyways :)
It depends on
a) Your traffic levels b) Your server c) How expensive your queries are
For example, as a rule of thumb, I never go over 15 queries a page. However I allow for atleast 6-7 to be expensive (1-2 joins).
Anything thats only changes very rarely (movie descriptions as an example) I would cache. Then in administration, delete that cache file when that movie is updated.
However I have had sites that have 80 queries (back in the day) and had 200+ visitors constantly refreshing with no issue but they were all very light.
I don't think there's any real solid rule people will give or you should abide by.
精彩评论