hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : What's faster, multiple SQL columns or one and PHP sorting it?
Reply

Forum Jump

What's faster, multiple SQL columns or one and PHP sorting it?

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old
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.



Sponsored Links
  #2  
Old
WHT Addict
 
Join Date: Jan 2007
Posts: 158
Write a script and benchmark both as the result will depend entirely what your doing.

  #3  
Old
Web Hosting Master
 
Join Date: Mar 2010
Location: Upstate New York
Posts: 1,302
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

Sponsored Links
  #4  
Old
WHT 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.

  #5  
Old
WHT 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

Jonny

__________________
Evorack - The Server Has Evolved
UK, Germany, USA Xen & KVM 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

  #6  
Old
(formerly WhichGunDotCom)
 
Join Date: Jun 2011
Location: Woodbridge, NJ
Posts: 827
Quote:
Originally Posted by enigma-1 View Post
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.

  #7  
Old
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.

  #8  
Old
New Member
 
Join Date: Apr 2012
Posts: 4
my idea is one field and explode this columns.

  #9  
Old
(formerly WhichGunDotCom)
 
Join Date: Jun 2011
Location: Woodbridge, NJ
Posts: 827
Quote:
Originally Posted by misaf View Post
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.

  #10  
Old
New Member
 
Join Date: Apr 2012
Posts: 4
ok test it and see speed both

and then you understand my idea is true...

  #11  
Old
New Member
 
Join Date: Apr 2012
Posts: 2
Quote:
Originally Posted by f3tus View Post
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.

  #12  
Old
VP Of Twinkies
 
Join Date: Jan 2004
Location: Vancouver, BC
Posts: 1,095
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.

__________________
I'M A WEB DEVELOPER
I specialize in neck beards


Last edited by mg-; 05-04-2012 at 06:09 AM.
Reply

Similar Threads
Thread Thread Starter Forum Replies Last Post
Which is faster with SQL & PHP ? redtail Programming Discussion 13 02-26-2010 05:05 AM
Simple question regarding sorting SQL Result latheesan Programming Discussion 1 06-28-2008 02:26 PM
SQL display result: 2 columns? bear Employment / Job Offers 18 10-30-2005 09:02 AM
Is PHP hosting with mySQL faster than SQL Server? hostpulse Web Hosting 11 04-27-2004 07:02 PM
Binary Columns in Sql DB with PHP ? jonasf Programming Discussion 2 03-12-2003 12:47 AM

Related posts from TheWhir.com
Title Type Date Posted
Venture Capitalists Invest $33 Million in Databricks to Commercialize Apache Spark Web Hosting News 2014-07-01 11:13:40
The Network is the Bottleneck: Stacks and Flows Are the Answer Web Hosting News 2013-10-02 11:49:08
ServerPoint Launches New Cloud VPS Hosting Solution Web Hosting News 2013-07-12 09:20:41
GlobalSign Allows Multiple SSL Certificates on Single IP Address Web Hosting News 2013-03-08 10:31:27
Singaporean Web Host 8 to Infinity Launches Global Virtual Servers Web Hosting News 2013-02-28 12:19:00


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
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

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?