SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is field specification faster?

    Hi,

    Let us assume that I have a table with three fields called id, name and email. I want to retrieve all the fields. Which one of the following queries is best to use regarding execution speed?

    Code:
    SELECT * FROM table
    Code:
    SELECT id, name, email FROM table
    Yours, Erik.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,323
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    the second will be marginally faster based on speed, because in the first, the optimizer must first go get the column names out of the system table

    always using the second style as a matter of coding hygiene on all queries is better for other reasons, too
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Thanks for the explanation. I will use the second style from now on.

    Yours, Erik.

  4. #4
    SitePoint Guru
    Join Date
    Jan 2004
    Location
    Uppsala, sverige
    Posts
    698
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    the second will be marginally faster based on speed, because in the first, the optimizer must first go get the column names out of the system table
    The DBMS needs to get the names in any case so the cost for dictionary lookup will be the same.


Bookmarks

Posting Permissions

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