Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts

    Smile Select Queries - listing each required variable VS *

    Hi there.

    When using Select queries, does it really matter that much if you always use;

    SELECT * from table

    instead of

    SELECT item1, item2 FROM table

    Does this greatly affect the speed the query is processed?

    Cheers,
    Pat.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,613
    Thanks
    80
    Thanked 4,634 Times in 4,596 Posts
    Depends.

    If the table(s) have many large fields, then doing SELECT * could be much slower than selecting individual fields *IF* when you selected individual fields you did *NOT* include all the large one.

    Consider: MySQL is in a separate process than whatever you use to invoke it (PHP or any other code...even the command line client). So whatever data you SELECT has to be sent through some sort of inter-process communication from MySQL to the client. Inter-process data transfer is much slower than in-process. The more data you pass, the longer it takes.

    So even if there were zero overhead within MySQL (and there's more than zero! often not a lot more,but...) the time it takes to pass data from one process to the other could add up.

    General rule: SELECT only what you need for best performance.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Regular Coder
    Join Date
    Dec 2010
    Location
    London
    Posts
    339
    Thanks
    63
    Thanked 11 Times in 11 Posts
    Very helpful. Thank you.


  •  

    Posting Permissions

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