Posted: Mon Jan 08, 2007 3:36 pm
? Would you like to explain why you say this?Kieran Huggins wrote:Saving db queries is overrated, in my opinion. Database connections are expensive, simple queries: not so much.
.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
? Would you like to explain why you say this?Kieran Huggins wrote:Saving db queries is overrated, in my opinion. Database connections are expensive, simple queries: not so much.
.
matthijs wrote:? Would you like to explain why you say this?Kieran Huggins wrote:Saving db queries is overrated, in my opinion. Database connections are expensive, simple queries: not so much.
.
From: http://wiki.dreamhost.com/index.php/KB_ ... _ConueriesDreamhost Wiki wrote:Why do connections count so much towards conueries?
Database connections use far more system resources than the average database query does. Because of this, we want to encourage people to make as few connections as possible with their code. So we "penalize" each connection by making it worth so many conueries. You can do a lot of things to cut down the number of connections you make with your code - it all depends on your particular application.
One of our customers averages over 1300 queries per connection! Thanks to the design of his code, his "conueries" are basically just queries.
Another customer averages just one query per connection. What they've done is basically turn their "conueries" into 25 times their queries. This uses up the monthly allotment of conueries a lot faster than necessary, so you should try to keep those connections open as long as possible. It'll also make your site faster in the process.
Remember, it's possible, through the use of peristent connections, to not have to make a new connection to your database even on a new page load!
Keep in mind that if PHP is running as CGI (PHP-CGI) and not as an Apache module, you will not be able to use persistent connections.
This is true, but irrelevant. We're talking about connecting to a database, getting some stuff, and disconnecting. The connection will only be built once whether the tree is built using a single parent_id system or a left/right/level system.Kieran Huggins wrote:Dreamhost Wiki wrote:Database connections use far more system resources than the average database query does.
Code: Select all
mysql> select id, firstchild as child, nextsibling as next, name,url from list;
+----+-------+------+----------+----------------------------------------+
| id | child | next | name | url |
+----+-------+------+----------+----------------------------------------+
| 1 | 2 | NULL | mypage | NULL |
| 2 | 5 | 3 | section1 | NULL |
| 3 | 8 | 4 | section2 | NULL |
| 4 | 9 | NULL | section3 | NULL |
| 5 | NULL | 6 | google | http://www.google.com |
| 6 | NULL | 7 | Fidelity | http://www.401k.com |
| 7 | NULL | NULL | E*Trade | http://www.etrade.com |
| 8 | NULL | NULL | PHP | http://forums.devnetwork.net |
| 9 | NULL | 10 | manual | http://www.php.net/manual/en |
| 10 | NULL | NULL | mysql | http://dev.mysql.com/doc/refman/5.0/en |
+----+-------+------+----------+----------------------------------------+