查询大小估算

For the relational schemas of the campus card database given in problem 1, there are following assumptions:

ncard=10,000 , npos=100, ndetail=10,000,000

lcard=25, lpos=22, ldetail=29

V(campus, pos) = 6, V(location, pos) = 20

V(depart, card) = 100, V(name, card) = 5000

The value of attribute cdate in detail table is uniformly distributed between ‘2017-01-01’ and ‘2017-12-31’.

block size is 4K bytes.

size of B±tree pointer is 4 bytes.

card and detail tables are stored as sequential files based on search key cno.

there is a B±tree index on detail(cno).

(1) Estimate the size (i.e. number of records) returned by following SQL statement :

select d1.cno, d2.cno

from detail d1, detail d2

where d1.pno=d2.pno

and d1.cdate=d2.cdate

and d1.cdate between ‘2017-05-01’ and “2017-07-31’

首先,detail被pno给连接了起来。pno是pos的主码,很容易得知,pno一共100个不同的值。

而detail一共10,000,000条记录。也就是说,一条pno对应了10,000,000/100条detail

也就是说,1条pno两侧分别有100,000条detail,它们笛卡尔积的大小就是(100,000)^2,

既然有100条pno,那么它们的大小为100*100,000^2。

由此,可以得到一个公式(由于我的概率论不太好,只能用这种方式算概率),假如一个集合大小为n, 一个集合大小为m,连接它们的属性一共k个,那么一个属性分别对应n/k, m/k个属性,结果为n*m/k个,概率为1/k。

简而言之,概率就是连接它们的属性个数倒数。

对于and连接的条件,概率相乘,第一次连接,概率为1/100.

由于一年有365天,因此第二个连接属性的大小为365

最后一个条件不涉及连接,更加简单,就是3/12

结果就是:(10,000,000)*(10,000,000)/(100*365)*3/12

这个算法需不需要m=k或者n=k呢?好像不需要。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值