Results 1 to 12 of 12
-
04-18-2012, 05:30 AM #1Newbie
- 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 #2WHT Addict
- Join Date
- Jan 2007
- Posts
- 158
Write a script and benchmark both as the result will depend entirely what your doing.
-
04-18-2012, 08:52 AM #3Web Hosting Master
- Join Date
- Mar 2010
- Location
- Upstate New York
- Posts
- 1,452
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...
████ John Rasri
████ Private Label Live Chat Provider For Resellers
████ GotLiveChat.com
████ White Label/Brand-able live chat software solutions
-
04-18-2012, 12:17 PM #4WHT Addict
- Join Date
- Mar 2012
- Posts
- 139
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 #5WHT Addict
- Join Date
- Aug 2010
- Posts
- 134
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
JonnyRackulous - Server Spectaculous
UK KVM & Xen VPS hosting since 2010
Windows & Linux Available | Native IPv6 | Gigabit Access Network | SSD and Spindle RAID10 Disk Storage
-
04-19-2012, 12:38 AM #6(formerly WhichGunDotCom)
- Join Date
- Jun 2011
- Location
- Woodbridge, NJ
- Posts
- 840
-
04-23-2012, 10:03 AM #7Newbie
- 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 #8New Member
- Join Date
- Apr 2012
- Posts
- 4
my idea is one field and explode this columns.
-
04-27-2012, 04:34 AM #9(formerly WhichGunDotCom)
- Join Date
- Jun 2011
- Location
- Woodbridge, NJ
- Posts
- 840
-
04-27-2012, 04:52 AM #10New 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 #11New Member
- Join Date
- Apr 2012
- Posts
- 2
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 #12VP Of Twinkies
- Join Date
- Jan 2004
- Location
- Toronto, ON
- Posts
- 1,104
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.
I specialize in neck beards
https://thatshirt.com
Similar Threads
-
Which is faster with SQL & PHP ?
By redtail in forum Programming DiscussionReplies: 13Last Post: 02-26-2010, 05:05 AM -
Simple question regarding sorting SQL Result
By latheesan in forum Programming DiscussionReplies: 1Last Post: 06-28-2008, 02:26 PM -
SQL display result: 2 columns?
By bear in forum Employment / Job OffersReplies: 18Last Post: 10-30-2005, 09:02 AM -
Is PHP hosting with mySQL faster than SQL Server?
By hostpulse in forum Web HostingReplies: 11Last Post: 04-27-2004, 07:02 PM -
Binary Columns in Sql DB with PHP ?
By jonasf in forum Programming DiscussionReplies: 2Last Post: 03-12-2003, 12:47 AM