How Slow Is Select *?
vettabase.com
vettabase.com
For instance, the statement that using select * will cause too many columns to be read is repeated over and over, but it mostly just isn't true. For instance, if I define a view that does select * from a join of two tables and then do a query that asks for two columns from the view, essentially every optimizer on the planet will push down the two columns and will never retrieve all the columns. The same applies to common table expressions.
Moreover, putting a * in these views or common expressions is actually less error prone than putting in an explicit field list. What you are saying is that the view or expression is passing everything through from a join or filter operation. That's the right thing.
This absolutist sort of generalization that select * needs to be repaired everywhere is just silly.
Never use SELECT * within the context of an application, as column additions or removals can break the app. It pays to be specific in code.
For interactive use, it's fine, especially when the exact spellings of the target columns is not known. The author might have more of a point on complex views.
Use a dictionary cursor, or some other method to convert whatever is returned into a hashmap like so: https://dev.mysql.com/doc/connector-python/en/connector-pyth...
D create table a (amb integer, a1 integer, a2 integer);
D create table b (amb varchar, b1 integer, b2 integer);
D insert into a values (1,1,1);
D insert into b values ('b',2,2);
D insert into b values ('b',1,3);
D select * from a, b where a.a1 = b.b1;
┌─────┬────┬────┬─────┬────┬────┐
│ amb │ a1 │ a2 │ amb │ b1 │ b2 │
├─────┼────┼────┼─────┼────┼────┤
│ 1 │ 1 │ 1 │ b │ 1 │ 3 │
└─────┴────┴────┴─────┴────┴────┘
D select amb from a, b where a.a1 = b.b1;
Error: Binder Error: Ambiguous reference to column name "amb" (use: "b.amb" or "a.amb")Oracle can certainly handle columnar formatted data. The in-memory columnar format is just what it says, HCC provides columnar compression and Exadata has done columnar data access forever.
I know little about Oracle specifically, but I do know that it is a huge beast with all kinds of feature that make generalization difficult.
To help with this problem, several databases now support a notion of "invisible columns", including Oracle, MySQL, and MariaDB. Invisible columns are excluded from SELECT *, but otherwise function like normal columns and can be queried explicitly by name.
Firstly, the account was completely disabled, so I couldn't log in to even see what was wrong, or to even make a change once I might figure it out. Secondly, they wouldn't tell me what the problem was. Eventually - 2 days later - someone from support said I were typing up their CPUs with my 'shitty SQL', and I should learn that 'select *' was garbage, and my client should hire a 'real developer'.
So... the server is having huge CPU spikes and clogging their network switch (got this over another couple days from another support person). After 8 days, the site/account was back online, and, the real culprit was one of the other 200 accounts on that shared server - they were blasting out spam.
But hey... yeah, have someone grep for "select *" and take immediate action. That it didn't actually stop the problem after a couple hours should have been the first clue.
That was my last direct experience with 'shared hosting' and one of my first "SQL snob" encounters.
The first one needs to read all data if used at the top level and the second one needs no actual data - just the overall row count, in whatever way is most optimal to calculate.
So this is basically still true today, although MySQL 8 has started to add parallelized reads to improve performance for this situation.
Never use *, you’ll thank yourself later on.
In many cases, I'd like that latter data transfer stage to be smarter. Give me back some smart object which represents a result set, but then lazily only retrieves the information my code actually uses. At the same time, try to predict what information I'll be needing from the result set to avoid server round trips. (If I'm iterating through a result set in order accessing 4 of the 8 columns, you can probably just batch send the data my code uses).
Basically, he wants a bunch of complexity and heuristics to be pushed into the query planner, the client, and the protocol, just so he doesn't have to write the column names.