
04-18-2012, 05:30 AM
|
|
Newbie
|
|
Join Date: Mar 2012
Posts: 8
|
|
What's faster, multiple SQL columns or one and PHP sorting it?
Basically, is it faster to have a table with 8 columns to go through, or is it faster to have a single one with the values separated by "," (like "a,b,c,d,e,f,g,h") and then let PHP sort them with explode(',',$string)?
Thanks.
|

04-18-2012, 06:27 AM
|
|
WHT Addict
|
|
Join Date: Jan 2007
Posts: 157
|
|
Write a script and benchmark both as the result will depend entirely what your doing.
|

04-18-2012, 08:52 AM
|
|
Web Hosting Master
|
|
Join Date: Mar 2010
Location: Upstate New York
Posts: 767
|
|
I'm thinking performance difference will be negligible since you're talking 8 fields. Now if it were hundreds of columns that would be another story...
|

04-18-2012, 12:17 PM
|
|
WHT Addict
|
|
Join Date: Mar 2012
Posts: 138
|
|
Depends on the implementation and future requirements. It may look simple to have multiple columns initially under a single entry, but later on you may need to increase the size of it, or sort the multiple columns etc. and that won't be fast nor easy to manage.
|

04-18-2012, 08:41 PM
|
|
WHT Addict
|
|
Join Date: Aug 2010
Posts: 132
|
|
Really, you should always store structured data in the proper form in SQL (i.e. by using columns). While I agree that using PHP Explode may be quicker than SQL when dealing with smaller (tiny) amounts of data, you loose all of the query goodness that SQL has to offer. Besides, there are many different SQL solutions out there. Don't just default to MySQL.
Cheers
Jonny
__________________
Evorack - The Server Has Evolved
UK Xen Managed and Unmanaged VPS hosting
Full Gigabit Access Network | Native IPv6 /64 Supported | RAID10 disk storage | 2 UK based Datacentres | Experienced Staff | Managed Firewall Service
OSes Available: Arch Linux, CentOS, Debian, Gentoo, NetBSD, Slackware, Trixbox (Asterisk PBX), Ubuntu
|

04-19-2012, 12:38 AM
|
|
(formerly WhichGunDotCom)
|
|
Join Date: Jun 2011
Location: Woodbridge, NJ
Posts: 684
|
|
Quote:
Originally Posted by enigma-1
Depends on the implementation and future requirements. It may look simple to have multiple columns initially under a single entry, but later on you may need to increase the size of it, or sort the multiple columns etc. and that won't be fast nor easy to manage.
|
Agreed. Use separate columns and store the data properly. Relying on tricks like that can create code maintainability problems in the long run.
|

04-23-2012, 10:03 AM
|
|
Newbie
|
|
Join Date: Apr 2012
Posts: 5
|
|
Storing your data in 8 different columns is a lot more flexible. If you run a search for database normalization you'll find a lot of articles explaining the reasons.
|

04-27-2012, 03:47 AM
|
|
New Member
|
|
Join Date: Apr 2012
Posts: 4
|
|
my idea is one field and explode this columns.
|

04-27-2012, 04:34 AM
|
|
(formerly WhichGunDotCom)
|
|
Join Date: Jun 2011
Location: Woodbridge, NJ
Posts: 684
|
|
Quote:
Originally Posted by misaf
my idea is one field and explode this columns.
|
As explained above by myself and others, that isn't a good way to do this.
|

04-27-2012, 04:52 AM
|
|
New Member
|
|
Join Date: Apr 2012
Posts: 4
|
|
ok test it and see speed both
and then you understand my idea is true...
|

04-30-2012, 05:08 PM
|
|
New Member
|
|
Join Date: Apr 2012
Posts: 2
|
|
Quote:
Originally Posted by f3tus
Basically, is it faster to have a table with 8 columns to go through, or is it faster to have a single one with the values separated by "," (like "a,b,c,d,e,f,g,h") and then let PHP sort them with explode(',',$string)?
Thanks.
|
Please don't combine 8 different pieces of data into a single database column. That violates basic database design. Each piece of data should be represented as it's own column. That way, you can get at each item individually, or all together, depending on what you're doing.
|

05-04-2012, 06:04 AM
|
|
VP Of Twinkies
|
|
Join Date: Jan 2004
Location: Vancouver, BC
Posts: 984
|
|
You're even doing the wrong way... the wrong way..
Why would you use explode when you would just serialize an array then save it, retrieve and unserialize. good way to break your content.
There are times where I've done similar things, moreso for storing settings, pulling 1 column and unserializing is faster and more reliable. what happens if you explode using , and you somehow have a comma in your input..
But again.. since you're sorting results it seems like... follow proper practces, otherwise you'll do something you think is acceptable in another area, and lose your career... or indirectly kill a kitten.. or both.
Hey, what's faster... pouring your own drink, or asking someone else to pour it for you.
Last edited by mg-; 05-04-2012 at 06:09 AM.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| Postbit Selector |
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
| Login: |
|
|
| Advertisement: |
|
|
| Web Hosting News: |
|
|
|