使用 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.
示例:
- 您有一个包含 20 列(C1、C2、...、C19 C20)的表 T.
- 你在 T 上有一个 (C1,C2) 的索引
- 你让
SELECT C1, C2 FROM T WHERE C1=123
- 优化器拥有索引的所有信息,不需要去表数据
相反,如果您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.
多个表的连接非常有用.
In joins for multiple tables is a lot helpful.
这篇关于使用 SELECT * 时的性能问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!