Why is SELECT * considered harmful?

0 votes
Sep 27 in Database by Daric
• 500 points
40 views

1 answer to this question.

0 votes
If you add fields to the table, they will automatically be included in all your queries where you use select *. This may seem convenient, but it will make your application slower as you are fetching more data than you need, and it will actually crash your application at some point.

There is a limit for how much data you can fetch in each row of a result. If you add fields to your tables so that a result ends up being over that limit, you get an error message when you try to run the query.

This is the kind of errors that are hard to find. You make a change in one place, and it blows up in some other place that doesn't actually use the new data at all. It may even be a less frequently used query so that it takes a while before someone uses it, which makes it even harder to connect the error to the change.

If you specify which fields you want in the result, you are safe from this kind of overhead overflow.

If you really want every column, I haven't seen a performance difference between select (*) and naming the columns. The driver to name the columns might be simply to be explicit about what columns you expect to see in your code.

Often though, you don't want every column and the select(*) can result in unnecessary work for the database server and unnecessary information having to be passed over the network. It's unlikely to cause a noticeable problem unless the system is heavily utilised or the network connectivity is slow.
answered Sep 27 by Omaiz
• 560 points

Related Questions In Database

0 votes
2 answers

Why is SELECT * table_name; is considered harmful?

Hi. Adding to @Tina's answer, there is ...READ MORE

answered Sep 23 in Database by Raghu
40 views
0 votes
1 answer

Is SELECT * harmful in Database?

There are really three major reasons: Inefficiency in ...READ MORE

answered Sep 7, 2018 in Database by DataKing99
• 8,130 points
55 views
0 votes
1 answer

Why is MongoDB preferred?

MongoDB is considered to be best NoSQL ...READ MORE

answered Jul 24, 2018 in Database by shams
• 3,580 points
55 views
0 votes
1 answer

Why is not preferable to use mysql_* functions in PHP?

The reasons are as follows: The MySQL extension: Does ...READ MORE

answered Sep 7, 2018 in Database by DataKing99
• 8,130 points
64 views
0 votes
1 answer

What is SELECT DISTINCT statement

This statement is used to return only ...READ MORE

answered Nov 21, 2018 in Database by darklord
• 6,190 points
52 views
0 votes
1 answer

What is the syntax of SELECT statement?

This statement is used to select data ...READ MORE

answered Nov 27, 2018 in Database by darklord
• 6,190 points
43 views
0 votes
1 answer

What is MSLAB and LZO?

MSLAB stands for Memstore-Local Allocation Buffer. Lempel-Ziv-Oberhumer (LZO) ...READ MORE

answered Jul 10, 2018 in Database by Data_Nerd
• 2,360 points
143 views
0 votes
1 answer

What is Functional dependency?

A relation is said to be in ...READ MORE

answered Aug 10, 2018 in Database by DataKing99
• 8,130 points
59 views
0 votes
1 answer

Which is faster/best? SELECT * or SELECT col1, col2,......colN

There are four big reasons that select * is ...READ MORE

answered Sep 27 in Database by Omaiz
• 560 points
26 views
0 votes
1 answer

How to select the nth row in a SQL database table?

To select nth row type the below ...READ MORE

answered Sep 27 in Database by Omaiz
• 560 points
31 views