读书人

mini-sql储存结构设计

发布时间: 2012-06-24 19:01:53 作者: rapoo

mini-sql存储结构设计

1. Table文件结构

-----------------------------------------------

Header (512B)

@Table Name (32B)

@File Crc32 (4B)

@Dump Flag (1B)

@Columns Count (1B = Max 8)

@Table Columns (Max 210B >= 196B = 24B*8 = 24B* @Columns Count)

@Column Name (16B)

@Column Data Type (4B)

@Column Data Size (4B)

@Primary Key (4B)

@Row Size (4B)

@Raw Data Size (4B)

-----------------------------------------------

@Row Index Table (2B*n)

1: @Row_i (2B)

2: @Row_j

...

n: @Row_k

-----------------------------------------------

@Raw Data (@Row Size* n = @Data Size)

@Row_1

@Row_2

@Row_3

...

@Row_n

-----------------------------------------------

1.1 创建Table文件

SQL请求 -> mini-sql解析器 -> 创建Table文件

1.2 插入行@ROW_x

按主键升序或降序插入行, 更新行索引表@Row Index Table, 直接插入行@ROW_x至@Raw Data尾部。

1.3 删除一些行

根据列条件约束,给出最佳查找算法,以最小访问存储器的时间为准。

删除完后,不直接重组数据,留下碎片,设定碎片标志位@Dump Flag,等系统空闲时再整理,以便快速回应处理结果给应用。

1.4 查询

根据列条件约束,给出最佳查找算法,以最小访问存储器的时间为准。

读出查询的数据,返回给应用。

1.5 删除Table文件

SQL请求 -> mini-sql解析器 -> 删除Table文件

端午节快乐~

thanks&best regards

mars.fu

June 23 2012, Saturday

ShenZhen Hot

mini-sql储存结构设计

If you have more info to communicate with me for this article, please feel free to

Q-me:270982354 or E-me: mars.fu@foxmail.com.

读书人网 >SQL Server

热点推荐