Results 1 to 12 of 12
  1. #1

    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.

  2. #2
    Write a script and benchmark both as the result will depend entirely what your doing.

  3. #3
    Join Date
    Mar 2010
    Location
    Upstate New York
    Posts
    1,415
    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

  4. #4
    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. #5
    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
    Rackulous - Server Spectaculous
    UK, Germany, Canada Xen & KVM 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. #6
    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. #7
    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. #8
    my idea is one field and explode this columns.

  9. #9
    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. #10
    ok test it and see speed both

    and then you understand my idea is true...

  11. #11
    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. #12
    Join Date
    Jan 2004
    Location
    Toronto, ON
    Posts
    1,100
    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
    Latest: Reach for Android

Similar Threads

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

Related Posts from theWHIR.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •