使用SELECT *时的性能问题? [英] Performance issue in using SELECT *?
问题描述
可能重复:
哪个更快/最好? SELECT *或SELECT column1,colum2,column3等
不使用select *的原因是什么?
使用SELECT *而不是SELECT FiledName,FiledName2 ...有什么性能问题吗?
Is there any performance issue in using SELECT * rather than SELECT FiledName, FiledName2 ... ?
推荐答案
的列,你给优化器不好的帮助(不能选择索引,或不能只到索引,...)
If you need a subset of the columns, you are giving bad help to the optimizer (cannot choose for index, or cannot go only to index, ...)
某些数据库可以选择检索仅来自索引的数据。这个东西是非常非常有益的,给了一个令人难以置信的加速。运行SELECT *查询不允许这个技巧。
Some database can choose to retrieve data from indexes only. That thing is very very helpfull and give an incredible speedup. Running SELECT * queries does not allow this trick.
无论如何,从应用程序的角度来看不是一个好的做法。
Anyway, from the point of view of application is not a good practice.
例如:
- 您在T上有一个索引(C1,C2) 您的表格T有20列(C1,C2,...,C19 C20)
- 您创建
SELECT C1,C2 FROM T WHERE C1 = 123
- 优化器具有所有信息索引,不需要去表数据
<
- You have a table T with 20 columns (C1, C2, ..., C19 C20).
- You have an index on T for (C1,C2)
- You make
SELECT C1, C2 FROM T WHERE C1=123
- The optimizer have all the information on index, does not need to go to the table Data
而是如果 SELECT * FROM T WHERE C1 = 123
,优化器需要获取所有列数据,然后不能使用索引(C1,C2)。
Instead if you SELECT * FROM T WHERE C1=123
, the optimizer needs to get all the columns data, then the index on (C1,C2) cannot be used.
多个表是很有帮助的。
这篇关于使用SELECT *时的性能问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!