SQL大小写和where条件与表的顺序

1.
SQL的大小写要看数据库类型, 如果数据库是Oracle, 则答案是B
SQL Server中, 可以手工设置数据库是否区分大小写, 所以SQL大小写对解析没有什么影响, 但是要注意的是, 一定要统一表名, SQL语句等等的格式, 统一大写或小写.
 
Oracle则不一样, SQL设置为统一为大写时性能更优, 虽然比小写时性能高不了多少.
以下内容摘自Oracle官方的数据库调优手册:
Shared Pool Concepts目录下的Library Cache Concepts目录下的SQL Sharing Criteria中写到:
Many Oracle products, such as Oracle Forms and the precompilers, convert the
SQL before passing statements to the database. Characters are uniformly changed
to uppercase, white space is compressed, and bind variables are renamed so that a
consistent set of SQL statements is produced.
 
Accepting a SQL Profile 目录下写道: 
Typically, an accepted SQL Profile is associated with the SQL statement through a
special SQL signature that is generated using a hash function. This hash function
normalizes the SQL statement for case (changes the entire SQL statement to upper
case) and white spaces (removes all extra whites spaces) before generating the
signature.
 
以上两处提到系统强制转换SQL为大写, 所以如果sql写成小写, 则会有额外的开销
 
其他类型数据库我没有去考证, 如果有相关资料请告知
 
2.
答案也是要看条件, 如果在A,B,C表中数据量相当, 则答案是B
 
因为oracle数据库有两种优化器
RBO - 1、 基于规则的优化方式(Rule-Based Optimization,简称为RBO) 优化器 
CBO - 1、 基于代价的优化方式(Cost-Based Optimization,简称为CBO) 优化器
如果是RBO优化器,  ORACLE 的解析器按照从右到左的顺序处理FROM子句中的表名,FROM子句中写在最后的表(基础表 driving  table)将被最先处理.
如果是CBO优化器, ORACLE则优先处理输出数据量少的表.

转载于:https://www.cnblogs.com/dushuai/articles/3256126.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值