Asterisk In Select Query

Posted on 2006-05-18
Last Modified: 2008-03-17
I have a query that does something like the following:

SELECT d.*, a.* FROM TABLE1 d, TABLE2 a WHERE ......

Is there a degradation in performance or are the indexes ignored by using the d.* and a.* instead of the actual column names like d.COLUMN1, d.COLUMN2, a.COLUMN1, a.COLUMN2?  Thanks.

BTW, I am using SQL Server 2000, 2005 and Oracle 9 and 10.
Question by:pcarrollnf
    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    > Is there a degradation in performance or are the indexes ignored by
    > using the d.* and a.* instead of the actual column names

    there wont be any degradation in performanxce
    LVL 44

    Assisted Solution

    Hi pcarrollnf,

    The indexes are not ignored, however there is a slight degradation in performance because the server needs to enumerate the fields. When you specify fields, there is nothing that needs to be done, however if you use * then the server must first get the full field list then prepare the actual query. This does ever so slightly (and possibly not even measurably) degrade your performance. However once the field list is obtained then the normal execution plan will be generated and used.

    Tim Cottee
    LVL 142

    Accepted Solution

    it is preferrable to avoid the *, because
    * you gain a minimum avoiding sql to resolve the * into the actual column list
    * you should only return those columns (and rows) that you really need

    indexes will not be ignored due to this, but you have indexes that contain all the fields that are in the list, the table page does not need to be looked up.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    APEX (Application Express) is used to develop a web application from Oracle. SQL Workshop is one of the tools that comes with Oracle APEX to query or modify the database objects or to make any changes to the structure.
    Read about achieving the basic levels of HRIS security in the workplace.
    Video by: Steve
    Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now