TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-24-2008, 09:07 AM   #1 (permalink)
The Wanderer
 
kokjj87's Avatar
 
Join Date: Oct 2008
Posts: 18
Thanks: 0
kokjj87 is on a distinguished road
Default Does Count(*) consume more memory?

Just wondering does of both of them consume the same amount of memory??... let say i have 5 column in the table.

PHP Code:
Select count(*) from table

Select count
(idfrom table 
kokjj87 is offline  
Reply With Quote
Old 12-24-2008, 03:28 PM   #2 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Although I cant say for sure, but count(*) would in theory take more since it has to find what all the columns are and count them.
__________________

Village Idiot is offline  
Reply With Quote
Old 12-24-2008, 03:49 PM   #3 (permalink)
The Wanderer
 
geo353's Avatar
 
Join Date: Dec 2008
Location: Wiltshire, UK
Posts: 13
Thanks: 0
geo353 is on a distinguished road
Default

i think they would both use about the same seeing as whichever you use they both just count the nunber of rows.
geo353 is offline  
Reply With Quote
Old 12-24-2008, 03:51 PM   #4 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Quote:
Originally Posted by geo353 View Post
i think they would both use about the same seeing as whichever you use they both just count the nunber of rows.
But the wildcard key gives SQL more to do, SELECT * FROM table is almost always slower than SELECT id,username,othercolumn1,ect FROM table
__________________

Village Idiot is offline  
Reply With Quote
Old 12-24-2008, 03:59 PM   #5 (permalink)
The Wanderer
 
geo353's Avatar
 
Join Date: Dec 2008
Location: Wiltshire, UK
Posts: 13
Thanks: 0
geo353 is on a distinguished road
Default

i understand that but, and i may be wrong, count is optimized for speed and regardless of the selected column the number of rows will always be the same. so i dont see why this should affect the speed. i might be wrong though.
geo353 is offline  
Reply With Quote
Old 12-24-2008, 04:01 PM   #6 (permalink)
Wizard
Top Contributor 
 
Village Idiot's Avatar
 
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
Village Idiot is on a distinguished road
Default

Saying * still makes it resolve for every row in the table, not a giant difference, but using * will be slower.
__________________

Village Idiot is offline  
Reply With Quote
Old 12-24-2008, 05:01 PM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Have a read of this, its very interesting.
http://www.mysqlperformanceblog.com/...t-vs-countcol/
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory Caching Orc General 4 11-11-2008 11:48 AM
Getting structure of resultset in memory Dave MySQL & Databases 3 05-24-2008 12:53 PM
virtual memory leak shiggle Absolute Beginners 2 02-26-2008 08:55 AM
Firefox slowness caused by memory fragmentation Wildhoney General 22 12-09-2007 04:36 PM
Memory Management with Declare Wildhoney Advanced PHP Programming 2 10-18-2007 03:44 PM


All times are GMT. The time now is 04:14 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design