讨论最优化的sql如何写
数据库10g条件:
表1(表名t1,行数很多)
字段如下:
bh INT, --建有普通索引
xm Varchar2(30),
xb VARCHAR2(1) --取值只有0和1
表2(表名t2,行数较少)
字段如下:
bh INT, --建有普通索引
sfzhm Varchar2(18),
dz VARCHAR2(100)
其中t1.bh=t2.bh
统计结果为:
select count(a.bh) from t1 a,t2 b where a.bh=b.bh and a.xb='0' 这么简单连接和结构
select /*+USE_HASH(b a)*/count(a.bh) from t1 a,t2 b where a.bh=b.bh and a.xb='0'
在xb建一个bit map索引
普通索引能改为唯一索引更好 select count(a.bh) from t1 a,t2 b where a.bh=b.bh and a.xb='0'
直接根据t1表查询不就得了,为什么要加t2表?不就是想统计性别为0的人数吗?
页:
[1]