LanceT Posted April 21, 2007 Share Posted April 21, 2007 Having little knowledge of efficiency, I was wondering which would be more efficient for counting a user's number of posts for a forum. Option 1 Selecting the total number of posts and topics that the user has made Option 2 Having a user field that keeps track of the number of posts and topics, which is incremented / decreased every time a post is made or deleted. Thanks. Link to comment https://forums.phpfreaks.com/topic/48051-which-is-more-efficient-for-a-forum/ Share on other sites More sharing options...
dustinnoe Posted April 21, 2007 Share Posted April 21, 2007 Option 2 Link to comment https://forums.phpfreaks.com/topic/48051-which-is-more-efficient-for-a-forum/#findComment-234853 Share on other sites More sharing options...
keeB Posted April 21, 2007 Share Posted April 21, 2007 Creating the proper indexes on the table will yield negligible performance increases in storing the users posts in a field. Not to mention, it's a PITA to have to keep updating the number of posts a user has using method 2. My recommendation is option1. Link to comment https://forums.phpfreaks.com/topic/48051-which-is-more-efficient-for-a-forum/#findComment-234870 Share on other sites More sharing options...
leesiulung Posted April 21, 2007 Share Posted April 21, 2007 I must agree with KeeB, hands down option 1. A smart database will cache your query and it will only be costly the first time the query is called. In addition, you can set the field in a session. The cost should be negligable. Do not try to optimize the database with fancy tricks unless you know it will have a significant performance gain. Let the database do what it is intended to do. Optimize only if needed.... Link to comment https://forums.phpfreaks.com/topic/48051-which-is-more-efficient-for-a-forum/#findComment-234921 Share on other sites More sharing options...
LanceT Posted April 22, 2007 Author Share Posted April 22, 2007 A smart database will cache your query and it will only be costly the first time the query is called. In addition, you can set the field in a session. The cost should be negligable. Don't really know how to cache queries, does mysql do this automatically or do I have to setup something different? Please help! Link to comment https://forums.phpfreaks.com/topic/48051-which-is-more-efficient-for-a-forum/#findComment-235457 Share on other sites More sharing options...
leesiulung Posted April 24, 2007 Share Posted April 24, 2007 A smart database will cache your query and it will only be costly the first time the query is called. In addition, you can set the field in a session. The cost should be negligable. Don't really know how to cache queries, does mysql do this automatically or do I have to setup something different? Please help! I'm not as familiar with MySQL/PHP, but most databases I encounter, can do stored procedures. In some languages you can also specify to cache the query, for ColdFusion that is with cachedwithin attribute and for Java/JSP you can use PreparedStatements. Perhaps, somebody else can shed some light on how to do this in PHP/MySQL. I'm sure they have an equivalent or do some Google searches. Hope this helps... Link to comment https://forums.phpfreaks.com/topic/48051-which-is-more-efficient-for-a-forum/#findComment-237014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.