Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 9th, 2006, 11:58 PM   #1
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 364
Rep Power: 0 King is an unknown quantity at this point
SQL Select Statement Performance

This is probably a dumb question, but I’ll ask anyways. I have an application that has a GetAll() function that gets all the records from a Customer table in a MS Access database. I just use a select statement that looks like this:
SELECT * FROM Customer;
I use this function a fair bit throughout my application for different things. Sometimes I only want the first and last name from the record; so should I make another function for this and go:
SELECT FirstName, LastName FROM Customer;
Would doing this make all that much of a difference performance wise, because if it doesn’t I won’t bother changing it in my code. There are about 10 other fields in the Customer table other than FirstName and LastName, so I was thinking maybe if it only had to get the two fields it my save some time a bit of memory. What do you guys think?
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Aug 10th, 2006, 12:03 AM   #2
big_k105
PFO Founder

 
big_k105's Avatar
 
Join Date: Mar 2004
Location: Fargo, ND
Posts: 1,613
Rep Power: 10 big_k105 is on a distinguished road
Send a message via AIM to big_k105 Send a message via MSN to big_k105 Send a message via Yahoo to big_k105
I don't think it will make that big of a difference. Either way it still has to grab every row from the table. But then again it kind of depends on how large the table is. If it is really really big then it would probably make a difference but if its not huge then it might not make that much of a difference. I guess the best way to find out is to try it and see what happens.
__________________
BIG K aka Kyle
Programming Forums
Kyle K Online

Please do not PM or email me programming questions. Post them in the forums instead.
big_k105 is offline   Reply With Quote
Old Aug 10th, 2006, 12:08 AM   #3
Booooze
Expert Programmer
 
Booooze's Avatar
 
Join Date: Mar 2006
Location: Igloo
Posts: 708
Rep Power: 3 Booooze is on a distinguished road
Send a message via MSN to Booooze
You know what, unless it's a big heavy program dependant on a heavy db, I don't think it's going to matter. From what you say, it doesn't sound like it's not going to hurt to make an extra sql command here or there. Unless the db is remote, or under heavy usage, I wouldn't bother. In a recent db program I made, I had lots of calls to a mysql db, and didn't seem slow at all. The question is: Is the change in code going to make a difference in speed or performance noticable to the user(s)? Because a user can't really count in nano seconds.
Booooze is offline   Reply With Quote
Old Aug 10th, 2006, 6:52 AM   #4
jim mcnamara
Hobbyist Programmer
 
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4 jim mcnamara is on a distinguished road
Also.

When you have a WHERE clause you return fewer records, using less direct I/O compared to a full-table scan. This gets down to size of the table - ie., number of records in the table. You are doing a defacto full table scan and retreive with your current SQL.

In other words, if you had an index on the field(s) in the query, and if you were using a where clause and if there were say 20000+ records in Customer, then you would speed things up a noticeably by using a restricted query.
jim mcnamara is offline   Reply With Quote
Old Aug 10th, 2006, 8:55 AM   #5
King
Professional Programmer
 
King's Avatar
 
Join Date: Jan 2006
Location: Ontario, Canada
Posts: 364
Rep Power: 0 King is an unknown quantity at this point
yea I doubt this table will ever have more than 100 to 200 records. Maybe after I load it with that much test data I will try different things to see if I see a difference. As Booooze said, a user can't count nano seconds. Thanks for the input guys.
__________________
I am Addicted to Linux!
King is offline   Reply With Quote
Old Aug 10th, 2006, 11:35 AM   #6
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 742
Rep Power: 3 Jimbo is on a distinguished road
Quote:
Originally Posted by King
yea I doubt this table will ever have more than 100 to 200 records.
Famous words from the design stage. Even if it is a small project you might as well make a scalable solution... unless of course, you actually need every single record...
Jimbo is offline   Reply With Quote
Old Dec 1st, 2006, 5:12 PM   #7
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 314
Rep Power: 4 mackenga is on a distinguished road
There are no scalable solutions that use Access databases! Anyway, enough prejudice...

It seems eminently reasonable just to go on SELECTing * - but I have to admit I'd rather do some more selective SELECTing where possible. Performance probably won't improve significantly, but it'll give you a warm cosy feeling. Especially when you unexpectedly gain a few thousand customers (but then I guess if that happens you'll be getting a warm cosy feeling from your bank account anyway).
__________________
"I'm not a genius. Why do I have to suffer?"
mackenga is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Slackware installation guide for Linux beginners coldDeath Coder's Corner Lounge 104 Jul 29th, 2007 4:40 AM
Slow Performance Counter coder0xff C++ 2 May 31st, 2006 9:29 PM
Process Id to Performance Counter Name coder0xff C++ 1 May 29th, 2006 11:19 AM
reloading html select boxs...is there a better way? MegaArcon Python 13 May 26th, 2006 3:06 AM
sockets, problem with select() Wizard1988 C++ 0 Jan 15th, 2006 4:09 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:28 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC