[solved] Two things I've always wondered.

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

[solved] Two things I've always wondered.

Post by Mightywayne »

(regarding php)

1. When choosing mysql_fetch_assoc, instead of fetch_array, how much strain do you think that saves?

2. Let's say I am fetching an entry from a table that has 10 fields in it. Would that be slower than a table that had 2 fields in it?
Last edited by Mightywayne on Tue Sep 18, 2007 8:23 pm, edited 1 time in total.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

It will most likely be immeasurable unless is under really heave load. Worry about these kind of things later after your applicatiton is complete, otherwise it will never get done.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

If he worries about these things after his app is built, then he'll have to go back & change it later. Better to think these things out in advance.

~Begby is right though in that it'll probably be immeasurable until there's a huge load. A good bet would be to built a test case. Make a script that accesses your database 1000 times. You can use microtime() to time it. Run it once with mysql_fetch_assoc() and once with mysql_fetch_array(). If the times are very close, up your accesses to 2000, 3000 or whatever it takes until a clear winner is shown.

Yes, a table with 10 fields will be slower (although microscopically) than a table with 2 fields - since there's more data to chunk through. However, its much faster than having 5 tables with 2 fields & doing some query magic to get all the fields.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Super idea, Pickle! Thanks mang. Out of interest and thanks, I'll post my findings here.
Mightywayne
Forum Contributor
Posts: 237
Joined: Sat Dec 09, 2006 6:46 am

Post by Mightywayne »

Back! When I get back home, (like an hour) I'll do more testing, but wow.

3,000 queries and fetched, took .16 seconds average.

With assoc_, it was .14 seconds. :P

Thanks a lot. I think on a rainy day I'll go through my most popular scripts, and fix it up. With 30 users, I guess I needn't worry much. =P
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Something else to bear in mind with select is where possible don't use SELECT *, only return those columns you need. That does make a substantial difference for large tables, especially if you do not need some text columns.
Post Reply