-
相比于 hash heap sorted file structure 尽管对page cost 读取进行了优化但是面对大量数据的操作时候还是很耗费时间,所以引入index概念。
Index 存储在index page里面 包含 Id, PageId 大大减少了 page cost,查找所需要读取的page 数目大大减少。 -
selection 分类:一维 1-d、n维 n-d、 similarity 又分为 有index 和 no index 并包括不同的file structures
-
primary key 都是带有index 的
-
Implementing Select Efficiently:
sorting (search strategy)
hashing (static, dynamic, n-dimensional)
index files (primary, secondary, trees)
signatures (superimposed, disjoint) -
insertion in heaps
get_page(rel,pid,buf);
page cost = 1 read + 1 write
-
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,对数据库空间进行优化。 -
index 分类
sorted
hash
signature
b+tree
bits -
sorted files
search page cost : logN -
hash 存在的问题
1 11 21 31 当 k = 10 的时候 在同一个page里面
需要定时更改k 来避免出现这种问题
flexible hashing
linear hashing -
重点 linear hashing
splitting 要区分开:
overpage 满了 split
or page 满了 split
or 6个插入之后split
or 第六个插入之前 split
PostgreSQL fifth class
最新推荐文章于 2024-09-26 12:23:07 发布