PostgreSQL fifth class

  1. 相比于 hash heap sorted file structure 尽管对page cost 读取进行了优化但是面对大量数据的操作时候还是很耗费时间,所以引入index概念。
    Index 存储在index page里面 包含 Id, PageId 大大减少了 page cost,查找所需要读取的page 数目大大减少。

  2. selection 分类:一维 1-d、n维 n-d、 similarity 又分为 有index 和 no index 并包括不同的file structures

  3. primary key 都是带有index 的

  4. Implementing Select Efficiently:

    sorting (search strategy)
    hashing (static, dynamic, n-dimensional)
    index files (primary, secondary, trees)
    signatures (superimposed, disjoint)

  5. insertion in heaps

    get_page(rel,pid,buf);
    

    page cost = 1 read + 1 write

  6. delete 操作

    每一条record遍历删除

    //SQL:  delete from R  where Condition
    
    //Implementation of deletion:
    
    rel = openRelation("R",READ|WRITE);
    for (p = 0; p < nPages(rel); p++) {
        get_page(rel, p, buf);
        ndels = 0;
        for (i = 0; i < nTuples(buf); i++) {
            tup = get_record(buf,i);
            if (tup satisfies Condition)
                { ndels++; delete_record(buf,i); }
        }
        if (ndels > 0) put_page(rel, p, buf);
        if (ndels > 0 && unique) break;
    }
    

    当record 删除之后 page 空的 怎么办?
    两种情况:
    一是留着空page,等下次insert时候 把record insert into this empty page。
    二是定时回收empty page
    如果page 空间为 1000, 第一个page 存了1, 第二个page 存了2, 明显这两个page都在浪费空间,采取策略:压缩page,对数据库空间进行优化。

  7. index 分类
    sorted
    hash
    signature
    b+tree
    bits

  8. sorted files
    search page cost : logN

  9. hash 存在的问题
    1 11 21 31 当 k = 10 的时候 在同一个page里面
    需要定时更改k 来避免出现这种问题
    flexible hashing
    linear hashing

  10. 重点 linear hashing
    splitting 要区分开:
    overpage 满了 split
    or page 满了 split
    or 6个插入之后split
    or 第六个插入之前 split

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值