Skip to content

Latest commit

 

History

History
179 lines (110 loc) · 41.9 KB

internal.md

File metadata and controls

179 lines (110 loc) · 41.9 KB

WSQL Internal Manual Documentation

Framework

framework

Layout of table

For example, table tb1 is consisted of:

name    STRING[256]
age     INT
height  FLOAT

There will be 7 files on disk to make this table:

tb1.scm           // stores the defination of the table 
tb1.name.data     // stores the data of 'name' column
tb1.name.index    // stores the index of 'name' column
tb1.age.data      // stores the data of 'age' column
tb1.age.index     // stores the index of 'age' column
tb1.height.data   // stores the data of 'height' column
tb1.height.index  // stores the index of 'height' column

For each line of entry, the RID of each column in its .data file should keep the same.

Behind insert into

If the value at some column was not given, then it will be set to NULL.

For each column:

  • Insert the column value into its .data file, get the RID.
  • Insert (RID, value) to .index file.

Behind delete from ... where ...

Firstly look through all the .index files to filter out the RIDs of entries corresponding to 'where ...'.

For each RID above:

  • delete the data it points to in each .data file.

PageFile

Layout of PageFile

The data was stored to disk or loaded from disk in the granularity of page.

OFFSET                          CONTENT

+ 0  ------------------------------------------    
|                                             
|                                 PF_FileHdr       
|                                                 
| PAGESIZE                    -----------------   
|                                 PF_PageHdr      \
| PAGESIZE+sizeof(PF_PageHdr) -----------------    | 
|                                                   > page 0
|                                 data             |
|                                                 /
| 2*PAGESIZE                  -----------------   
|                                 PF_PageHdr      \
| PAGESIZE+sizeof(PF_PageHdr) -----------------    |
|                                                   > page 1
|                                 data             |
|                                                 /
| 3*PAGESIZE                  -----------------
| 

...


PF_PageHandle

  • PF_PageHandle (const PF_PageHandle &pageHandle)

This method is the copy constructor. When a new page handle object is created from a page handle object that refers to a pinned page in the buffer pool, the page is not pinned a second time.

  • PF_PageHandle& operator= (const PF_PageHandle &pageHandle)

This method overloads the = operator when it is used to assign one page handle object to another. As with the copy constructor, if the page handle object on the right-hand side of the = refers to a pinned page, the page is not pinned a second time.

  • RC GetData (char *&pData) const

This method provides access to the actual contents of a page. The PF_PageHandle object for which this method is called must refer to a page that is pinned in the buffer pool. If the method is successful, pData is set to point to the contents of the page in the buffer pool.

  • RC GetPageNum (PageNum &pageNum) const

This method sets pageNum to the number of the page referred to by the PF_PageHandle object for which this method is called. The page handle object must refer to a page that is pinned in the buffer pool.

PF_FileHandle

  • PF_FileHandle (const PF_FileHandle &fileHandle)

This method is the copy constructor, called if a new file handle object is created from an existing one. When a new file handle object is created from a file handle object that refers to an open file instance, the file is not opened an additional time. Instead, both file handle objects refer to the same open file instance. It is sufficient to call PF_Manager::CloseFile with one of the file handle objects to close the file.

  • PF_FileHandle& operator= (const PF_FileHandle &fileHandle)

This method overloads the = operator when it is used to assign one file handle object to another. It is not a good idea to assign one file handle object to another if the file handle object on the left-hand side of the = already refers to an open file. As with the copy constructor, if the file handle object on the right-hand side of the = refers to an open file instance, the file is not opened an additional time. Instead, both file handle objects refer to the same open file instance, and it is sufficient to call PF_Manager::CloseFile with one of the file handle objects to close the file.

  • RC GetFirstPage (PF_PageHandle &pageHandle)

For this and the following methods, it is a (positive) error if the PF_FileHandle object for which the method is called does not refer to an open file. This method reads the first page of the file into the buffer pool in memory. If the page fetch is successful, the pageHandle object becomes a handle for the page. The page handle is used to access the page's contents (see the PF_PageHandle class description below). The page read is automatically pinned in the buffer pool and remains pinned until it is explicitly unpinned by calling the UnpinPage method (below). This method returns the positive code PF_EOF if end-of-file is reached (meaning there is no first page).

  • RC GetLastPage (PF_PageHandle &pageHandle)

This method reads the last page of the file into the buffer pool in memory. If the page fetch is successful, the pageHandle object becomes a handle for the page. The page read is automatically pinned in the buffer pool and remains pinned until it is explicitly unpinned by calling the UnpinPage method (below). This method returns the positive code PF_EOF if end-of-file is reached (meaning there is no last page).

  • RC GetNextPage (PageNum current, PF_PageHandle &pageHandle)

This method reads into memory the next valid page after the page whose number is current. If the page fetch is successful, pageHandle becomes a handle for the page. The page read is pinned in the buffer pool until it is unpinned by calling the UnpinPage method. This method returns PF_EOF if end-of-file is reached (meaning there is no next page). Note that it is not an error if current does not correspond to a valid page (e.g., if the page numbered current has been disposed of).

  • RC GetPreviousPage (PageNum current, PF_PageHandle &pageHandle)

This method reads into memory the valid page previous to the page whose number is current. If the page fetch is successful, pageHandle becomes a handle for the page. The page read is pinned in the buffer pool until it is unpinned by calling the UnpinPage method. This method returns PF_EOF if end-of-file is reached (meaning there is no previous page). Note that it is not an error if current does not correspond to a valid page (e.g., if the page numbered current has been disposed of).

  • RC GetThisPage (PageNum pageNum, PF_PageHandle &pageHandle)

This method reads into memory the page specified by pageNum. If the page fetch is successful, pageHandle becomes a handle for the page. Parameter pageNum must be a valid page number. As usual, the page read is pinned in the buffer pool until it is explicitly unpinned.

  • RC AllocatePage (PF_PageHandle &pageHandle)

This method allocates a new page in the file, reads the new page into memory, and pins the new page in the buffer pool. If successful, pageHandle becomes a handle for the new page.

  • RC DisposePage (PageNum pageNum)

This method disposes of the page specified by pageNum. After this method is executed, if you scan over the pages of the file, the page numbered pageNum will no longer appear. It is a (positive) error to attempt to dispose of a page that is pinned in the buffer pool.

  • RC MarkDirty (PageNum pageNum)

This method marks the page specified by pageNum as "dirty," indicating that the contents of the page have been or will be modified. The page must be pinned in the buffer pool. A page marked as dirty is written back to disk when the page is removed from the buffer pool. (Pages not marked as dirty are never written back to disk.)

  • RC UnpinPage (PageNum pageNum)

This method tells the PF component that the page specified by pageNum is no longer needed in memory.

  • RC ForcePages (PageNum pageNum = ALL_PAGES)

This method copies the contents of the page specified by pageNum from the buffer pool to disk if the page is in the buffer pool and is marked as dirty. The page remains in the buffer pool but is no longer marked as dirty. If no specific page number is provided (i.e., pageNum = ALL_PAGES), then all dirty pages of this file that are in the buffer pool are copied to disk and are no longer marked as dirty. Note that page contents are copied to disk whether or not a page is pinned.

PF_BufferMgr

Index

Indexing is implemented with B-Link Tree.

The implementation for B-link tree node is in src/btree_node.cc.

Indexing file was storaged in the format of PageFile above.

Each node storged in one page.

Query

CompOp Value	Comparison
EQ_OP	        equal (i.e., attribute = value)
LT_OP	        less-than (i.e., attribute < value)
GT_OP	        greater-than (i.e., attribute > value)
LE_OP	        less-than-or-equal (i.e., attribute <= value)
GE_OP	        greater-than-or-equal (i.e., attribute >= value)
NE_OP	        not-equal (i.e., attribute <> value)
NO_OP	        no comparison (when value is a null pointer)

Remarks

  • Lastest updated on 2021.3.3
  • At the beggining, WSQL was builded based on the PF component from RedBase in Stanford CS346.