MyBase® File Storage Structure Design Zhaokai@hit.edu.cn MyBase is a lightweight database management system (DBMS) that is designing. Mybase is a blueprint with an existing commercial DBMS, trying to design a "Simple" DBMS, which reflects the basic principles of the database management system. The current goal is: 1 support the subset of the SQL statement; 2 support the memory algorithm, that is, the query is less than the size of the current memory available space. The system structure of MyBase is shown below: Figure 1 MyBase system structure query optimizer is an important part of DBMS, we divide it into the execution engine. This article mainly introduces the design of MyBase's file system and file cache. 1: Design environment: Windows operating system, use Windows API implementation. Two: Data Storage: We mainly use the OS's file system to store tables and indexes. Three: Database data dictionary Organic Form: Database's dictionary stores in files ended in .dic, including each table established time, the number of omnits, the attribute of each tuple, the type of attribute , Length, whether it is the primary key, whether it is empty. 4: Storage Organization Mode of Database: Each table is stored in a file ended in .mdb. The tuples in the document are as follows: Figure 2 WORKARs in the files are as follows: • EG Create Table Student (ID INT Primary Key, Name Char (20) Not Null, Age Int Figure 3 For example, a marker is stored in a bitmap (this is also the storage method of SQLServer 2K), so the improvement to the storage structure is as follows: Figure 4 will store the empty flag in a bitmap form: read to the cache The gage of the Guanyuan Group's access control file will read in the cache of the table space, which explains how to access tuples in Cache. There is a memory structure for each attribute in a tuple, including whether the attribute value is empty, the name, the attribute length, the type of attribute, whether the primary key and point to this property value The pointer to the address in cache. It corresponds to Struct Tagattribute. The metadata structure for the control of the Cache tuple is as follows: Figure 6 Example 6: File system definition file system design (not complete ): //mybase_filesystem.h #ifndef __mybase_filesystem #define __mybase_filesystem #include
#include
#Define MAX_NAME_LENGTH 10 // Number attribute name length #define MAX_ATTRIBUTE_NUMBER 20 // attribute relationship #define TABLE_CACHE_SIZE 8192 // 8K #define TABLE_FILE_NAME_LENGTH 11 // 8 3 #define TABLE_SPACE_NUMBER 10 // tablespace number # define TYPE_FLOAT 0 #define TYPE_INT properties struct 1 #define TYPE_STRING 2 #define TYPE_DATE 3 #define TYPE_CHAR 4 #define pRIMARY_KEY 0 #define NOT_PRIMARY_KEY 1 #define NULLABLE 0 #define DIS_NULLABLE 1 // relationship tagAttribute {INT type; // the Type of property 4 CHAR NAME [MAX_NAME_LENGTH]; // Property Name 10 Char * PTR; / / This property is addressed in memory 4 uint length; // This property length 4 BOOL IS_PRIMARY_KEY; // Is the primary key 4 BOOL is_null; // nullable 4 CHAR reserved [2]; // reserved, 32 bytes to fill}; typedef struct tagAttribute Attribute; typedef struct tagAttribute * pAttribute; struct tagTableSpace {SYSTEMTIME create_table_date; // creation time of the relationship INT TUPLE_NUMBER; / / Total number of INT TUPLE_LENGTH; / / The length of each tuple of INT Attribute_Number; // This relationship is attribute_list [MAX_ATTRIBUTE_NUMBER]; / / This relationship property int current_index ; // Currently in the recording of records referred to in the buffer char * ptr_current_index; // Current Pointer Ca Cache currently in the buffer referred to [Table_CAC HE_SIZE]; // Cushion INT TUPLE_NUMBER_IN_CACHE; / / Currently Turn into Cache Metal Group Int Begin_index; / / The minimum value IND_INDEX currently int end_index; // current buffer in the current buffer hANDLE table_file_handle maximum index recording means; // file handle table CHAR table_file_name [TABLE_FILE_NAME_LENGTH]; // table file name BOOL is_table_file_open; // the file is open BOOL is_table_space_open; // determines whether the relation is open}; typedef struct tagTableSpace tableSpace; typedef struct tagTableSpace * pTableSpace; pTableSpace table_space [TABLE_SPACE_NUMBER]; INT iTableSpaceMap [TABLE_SPACE_NUMBER]; // record is empty table space bitmap and the underlying file // buffer operation BOOL Seek_Nth_Tuple_In_File (); // file The pointer is moved to the nth group BOOL Seek_First_TUPLE_IN_FILE (); // Move the file pointer to the first tuple seek_next_tuple_in_file (); // Move the file pointer to the next tuple of the current tuple BOOL Seek_previous_tuPle_in_file (); // Move the file to the previous group BOOL UPDATE_TABLE_SPACE_IN_FILE (); // update the file where the table space is located.