Home > Ask the Oracle Database / Applications Experts > Questions & Answers > Why "select star" is bad
Ask The Oracle Expert: Questions & Answers
EMAIL THIS

Why "select star" is bad

Rudy Limeback EXPERT RESPONSE FROM: Rudy Limeback

Pose a Question
Other Oracle Categories
Meet all Oracle Experts
Become an Expert for this site
>
QUESTION POSED ON: 09 March 2004
I want to display all 27 columns in my table. I used SELECT * ... Is this right? Or should I use all column names instead? Is there any performance issue, like one way is faster? Is there any disadvantage if I use SELECT * ...?

>

There are many reasons why "select star" is bad. Foremost is the harm this can do to performance.

Imagine using SELECT * to retrieve rows from a table which includes a TEXT or BLOB column. A TEXT or BLOB column is large, and is used to store data like the contents of a chapter in a book, or an image.

If you do not intend to display the TEXT or BLOB column, for example if you wanted a list of the last 25 entries this week, then it is immediately obvious that SELECT * is bad when you display the query results on the screen or printer. You don't see a list, you see many kilobytes of TEXT or BLOB data. This prompts some people to post questions like "How do I write SELECT * except for column x?" on database forums. Answer: you can't; you have to list the columns you want.

Programming languages which can format query results, however, allow the programmer to execute SELECT * queries, but then decide which columns to display. If the TEXT or BLOB column is not displayed, everything still looks okay. But bandwidth is wasted, several kilobytes per TEXT or BLOB column, times N rows returned, on every execution. In addition to wasted bandwidth, performance also suffers, especially if a sort is required, such as when DISTINCT or ORDER BY is specified.

The sad fact is that this bad situation is not immediately apparent. In a testing environment, the programmer may have, ahem, other priorities. During volume testing, the poor performance is noticed, but now the programmer has to perform emergency debugging on his own code, to rediscover which columns are actually needed by each module. And if your organization does not do volume testing, you may not realize that SELECT * is bad for performance until the program goes live.

That said, if you do actually need all columns, then SELECT * is fine, provided that you never change the table. Or the query.

For instance, if you needed to change the query, say to join to another table to get a count of related rows, you cannot say GROUP BY * so you have to list the individual columns anyway, even if you need all of them.

Skilled developers will always explicitly list the minimum set of columns needed. The SELECT list thus describes the data used by the code module, and so is self-documenting. Bandwidth is minimized and performance is optimized, especially considering the increased possibility that the query might be satisfied by a covering index.

See also Why Select * is bad for a couple of additional reasons from an ASP perspective.

For More Information


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary



Search and Browse the Expert Answer Center
Search and browse more than 25,000 question and answer pairs from more than 250 TechTarget industry experts.
Browse our Expert Advice



Oracle White Papers: Fusion Middleware
HomeNewsTopicsTipsAsk the ExpertsMultimediaWhite PapersProductsBlogs
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2003 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts