`
- 浏览:
782172 次
- 性别:
- 来自:
上海
-
比如下面的SQL语句性能有区别吗?
select * from PEOPLE where FirstName="F" and LastName="L"
select * from PEOPLE where LastName="L" and FirstName="F"
答案是顺序没有影响,因为SQL引擎自己会执行最优的计划,顺序由SQL引擎处理,并不是你写的这个顺序,真正影响性能的是你有没有建立合适的索引,比如有没有索引,是FirstName和LastName上分别有索引,还是有复合索引(FirstName, LastName)等?
Does order of where clauses matter in SQL
http://stackoverflow.com/questions/11436469/does-order-of-where-clauses-matter-in-sql
No, that order doesn't matter (or at least: shouldn't matter).
Any decent query optimizer will look at all the parts of the WHERE clause and figure out the most efficient way to satisfy that query.
I know the SQL Server query optimizer will pick a suitable index - no matter which order you have your two conditions in. I assume other RDBMS will have similar strategies.
What does matter is whether or not you have a suitable index for this!
In the case of SQL Server, it will likely use an index if you have:
an index on (LastName, FirstName)
an index on (FirstName, LastName)
an index on just (LastName), or just (FirstName) (or both)
On the other hand - again for SQL Server - if you use SELECT * to grab all columns from a table, and the table is rather small, then there's a good chance the query optimizer will just do a table (or clustered index) scan instead of using an index (because the lookup into the full data page to get all other columns just gets too expensive very quickly).
Does the order of fields in a WHERE clause affect performance in MySQL?
http://stackoverflow.com/questions/4035760/does-the-order-of-fields-in-a-where-clause-affect-performance-in-mysql
分享到:
Global site tag (gtag.js) - Google Analytics
相关推荐
模仿SQL语句的正则表达式练习,是我学习正则表达式过程中,对字符串经常sql语句匹配,达到练习正则表达式的目的。语句中包括了,"创建超级用户权限,"*.*"代表数据库里的所有数据,"root"代表超级用户名称,"%"代表...
Java正则表达式构造SQL语句Java正则表达式构造SQL语句Java正则表达式构造SQL语句
方法1、使用语言的for语句循环生成SQL语句中的“?”,类似这样: 新建方法 func placeholders(n int) string { var b strings.Builder for i := 0; i 0 { b.WriteString("?") } return b.String() } 调用...
C#将Lambda表达式转成Sql语句,根据自己看的文章手写出来的,并配有自己理解的注释,有需要的同学可以自行下载。
SQL修改表语句和正则表达式 修改表结构 行 列 约束 等语句 常用正则表达式
动态拼接sql语句工具类,拼接where后面语句 配合原生jdbc仿动态sql注入 if (ObjectUtil.isNotEmpty(maxLat)&&ObjectUtil.isNotEmpty(minLat)){ sqlParamList.add(new SqlParam("lat",minLat, SqlOpEnum.GE)); ...
MSSQL 性能监控 SQL语句 性能测试
影响SQL server性能的关键,sql语句分析,可以参考 影响SQL server性能的关键,sql语句分析,可以参考
怎样写SQL语句可以提高数据库的性能怎样写SQL语句可以提高数据库的性能
Oracle Sql语句转换成Mysql Sql语句java 源码,非常简单,只要给定源oracle sql语句地址,和生成目标文件地址运行即可。
32丨MySQL调优之SQL语句:如何写出高性能SQL语句?.html
Sql语句执行顺序Sql语句执行顺序Sql语句执行顺序Sql语句执行顺序Sql语句执行顺序Sql语句执行顺序Sql语句执行顺序
浅谈SQL语句的优化对应用程序性能的影响.pdf
可是实现SQL的自动生成,再也不用为调式SQL语句错误而烦恼了!
深入SQL语句性能调整深入SQL语句性能调整深入SQL语句性能调整
关于SQL语句在进入oracle库缓存之后的执行顺序的简析~!
SQL语句的执行原理及顺序,好好学习吧!哈哈!
sql="update数据表set字段名=字段值where条件表达式" sql="update数据表set字段1=值1,字段2=值2……字段n=值nwhere条件表达式" (3)删除数据记录: sql="deletefrom数据表where条件表达式" sql="deletefrom数据
基于Lambda表达式的SQL语句生成器SqlLink,增删改查……
sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句sql注入语句...