Documentation ¶
Index ¶
- Variables
- func HeapPageCreateEmptyPageData() []byte
- func Int64ToRaw(num int64) ([]byte, error)
- func ParseInt64(raw []byte) (int64, error)
- func PutInt64(buf []byte, num int64) error
- func RandString(length int) string
- func Seed(seed int64)
- func Sizeof(t interface{}) uintptr
- type BufferPool
- type Catalog
- type CatalogSchema
- type CatalogTDSchema
- type DBFile
- type Database
- type DbFileIterator
- type Field
- type Filter
- type HeapFile
- func (hf *HeapFile) DeleteTuple(*TxID, *Tuple) ([]Page, error)
- func (hf HeapFile) ID() string
- func (hf *HeapFile) InsertTuple(txID *TxID, tuple *Tuple) (ret []Page, err error)
- func (hf *HeapFile) Iterator(txID *TxID) DbFileIterator
- func (hf HeapFile) NumPagesInFile() int64
- func (hf HeapFile) ReadPage(pid PageID) (Page, error)
- func (hf HeapFile) TupleDesc() *TupleDesc
- func (hf *HeapFile) WritePage(page Page) error
- type HeapPage
- func (hp *HeapPage) Bitset() bitset.BitSet
- func (hp HeapPage) EmptyTupleNum() (ret int)
- func (hp HeapPage) HeaderSize() int
- func (hp *HeapPage) InsertTuple(tuple *Tuple) error
- func (hp HeapPage) IsDirty() *TxID
- func (hp *HeapPage) Iterator(txID *TxID) DbFileIterator
- func (hp *HeapPage) MarkDirty(txID *TxID)
- func (hp HeapPage) MarshalBinary() (data []byte, err error)
- func (hp HeapPage) NumOfTuples() int
- func (hp HeapPage) PageID() PageID
- func (hp HeapPage) TupleDesc() *TupleDesc
- type HeapPageDbFileIterator
- type HeapPageID
- type IntField
- type Iterator
- type Op
- type OpIterator
- type Page
- type PageID
- type Permission
- type Predicate
- type RecordID
- type SeqScan
- type TdItem
- type Tuple
- type TupleDesc
- type TupleIterator
- type Tx
- type TxID
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( // DB singleton db DB = NewDatabase() // DefaultPageSize the os dependency pagesize DefaultPageSize = os.Getpagesize() // DefaultPageNum default page num DefaultPageNum = 50 )
var ( // IntType enum of Type int IntType = &Type{Name: reflect.TypeOf(int64(0)).Name(), Len: Sizeof(int64(0))} // StringType enum of Type string StringType = &Type{Name: reflect.TypeOf("").Name(), Len: 16} )
var ( // DefaultOrder default binary.LittleEndian DefaultOrder = binary.LittleEndian )
Functions ¶
func HeapPageCreateEmptyPageData ¶
func HeapPageCreateEmptyPageData() []byte
HeapPageCreateEmptyPageData create emptyPageDate
Types ¶
type BufferPool ¶
type BufferPool struct { // PageID2Page k is PageID.ID() PageID2Page map[string]Page // contains filtered or unexported fields }
BufferPool BufferPool manages the reading and writing of pages into memory from disk. Access methods call into it to retrieve pages, and it fetches pages from the appropriate location. <p> The BufferPool is also responsible for locking; when a transaction fetches a page, BufferPool checks that the transaction has the appropriate locks to read/write the page.
@Threadsafe, all fields are final
func (*BufferPool) GetPage ¶
func (bp *BufferPool) GetPage(tx *TxID, pid PageID, perm Permission) (ret Page, err error)
GetPage Retrieve the specified page with the associated permissions. Will acquire a lock and may block if that lock is held by another transaction. <p> The retrieved page should be looked up in the buffer pool. If it is present, it should be returned. If it is not present, it should be added to the buffer pool and returned. If there is insufficient space in the buffer pool, a page should be evicted and the new page should be added in its place.
func (*BufferPool) InsertTuple ¶
func (bp *BufferPool) InsertTuple(txID *TxID, tableID string, tuple *Tuple) error
InsertTuple insert tuple to page
func (BufferPool) PageSize ¶
func (bp BufferPool) PageSize() int
PageSize get the os dependencied page size
type Catalog ¶
Catalog The Catalog keeps track of all available tables in the database and their associated schemas.
func (Catalog) GetTableByID ¶
GetTableByID get DBFile/Table by tableID
func (Catalog) GetTableByName ¶
GetTableByName get DBFile/Table by name
type CatalogSchema ¶
type CatalogSchema struct { Filename string `json:"filename,omitempty"` TD []CatalogTDSchema `json:"td,omitempty"` TableName string `json:"table_name,omitempty"` }
CatalogSchema for load Catalog from file
type CatalogTDSchema ¶
type CatalogTDSchema struct { Name string `json:"name,omitempty"` Type string `json:"type,omitempty"` }
CatalogTDSchema for CatalogSchema
type DBFile ¶
type DBFile interface { ID() string ReadPage(pid PageID) (Page, error) WritePage(p Page) error InsertTuple(*TxID, *Tuple) ([]Page, error) DeleteTuple(*TxID, *Tuple) ([]Page, error) TupleDesc() *TupleDesc Iterator(*TxID) DbFileIterator }
DBFile The interface for database files on disk. Each table is represented by a single DBFile. DbFiles can fetch pages and iterate through tuples. Each file has a unique id used to store metadata about the table in the Catalog. DbFiles are generally accessed through the buffer pool, rather than directly by operators.
type Database ¶
type Database struct { Catalog *Catalog BufferPool *BufferPool }
Database singleton struct
type DbFileIterator ¶
type DbFileIterator interface { Iterator }
DbFileIterator DbFileIterator is the iterator interface that all newDB Dbfile should implement.
type Field ¶
type Field interface { fmt.Stringer encoding.BinaryMarshaler encoding.BinaryUnmarshaler Type() *Type Compare(Op, Field) bool }
Field identify one filed like int 1
type Filter ¶
type Filter struct { Child OpIterator Pred *Predicate Err error // contains filtered or unexported fields }
Filter is an operator that implements a relational projection.
func NewFilter ¶
func NewFilter(predicate *Predicate, child OpIterator) *Filter
NewFilter create new filter
type HeapFile ¶
HeapFile HeapFile
file format:
func NewHeapFile ¶
NewHeapFile new HeapFile
func (*HeapFile) DeleteTuple ¶
DeleteTuple del tuple to the HeapPage
func (*HeapFile) InsertTuple ¶
InsertTuple insert tuple to the HeapPage
func (*HeapFile) Iterator ¶
func (hf *HeapFile) Iterator(txID *TxID) DbFileIterator
Iterator DbFileIterator
func (HeapFile) NumPagesInFile ¶
NumPagesInFile get real num pages in file
type HeapPage ¶
type HeapPage struct { PID *HeapPageID TD *TupleDesc Head []byte Tuples []*Tuple TxMarkDirty *TxID }
HeapPage heap page
file format:
| header bit set | TupleTupleTupleTuple |
func NewHeapPage ¶
func NewHeapPage(pid *HeapPageID, data []byte) (*HeapPage, error)
NewHeapPage new HeapPage
func (HeapPage) EmptyTupleNum ¶
EmptyTupleNum num of empty tuple
func (HeapPage) HeaderSize ¶
HeaderSize computes the number of bytes in the header of a page in a HeapFile with each tuple occupying tupleSize bytes
func (*HeapPage) InsertTuple ¶
InsertTuple insert one tuple one the page
func (*HeapPage) Iterator ¶
func (hp *HeapPage) Iterator(txID *TxID) DbFileIterator
Iterator iterator
func (HeapPage) MarshalBinary ¶
MarshalBinary implement encoding.BinaryMarshaler
func (HeapPage) NumOfTuples ¶
NumOfTuples retrieve the number of tuples on this page.
type HeapPageDbFileIterator ¶
type HeapPageDbFileIterator struct { Err error // contains filtered or unexported fields }
HeapPageDbFileIterator HeapPage HeapPageDbFileIterator
func NewHeapPageDbFileIterator ¶
func NewHeapPageDbFileIterator(txID *TxID, hf *HeapFile) *HeapPageDbFileIterator
NewHeapPageDbFileIterator new HeapPageDbFileIterator with txID
func (HeapPageDbFileIterator) Error ¶
func (it HeapPageDbFileIterator) Error() error
Error return err
func (*HeapPageDbFileIterator) HasNext ¶
func (it *HeapPageDbFileIterator) HasNext() bool
HasNext has next
func (*HeapPageDbFileIterator) Next ¶
func (it *HeapPageDbFileIterator) Next() (ret *Tuple)
Next next
func (*HeapPageDbFileIterator) Open ¶
func (it *HeapPageDbFileIterator) Open() error
Open open the iterator
func (*HeapPageDbFileIterator) Rewind ¶
func (it *HeapPageDbFileIterator) Rewind() error
Rewind rewind the iterator
type HeapPageID ¶
HeapPageID HeapPageID
func NewHeapPageID ¶
func NewHeapPageID(tID string, pn int) *HeapPageID
NewHeapPageID new HeapPageID
func (HeapPageID) ID ¶
func (hid HeapPageID) ID() string
ID ${TableID}-${PageNum} identify the PageID
type IntField ¶
IntField int filed
func (IntField) Compare ¶
Compare Compare the specified field to the value of this Field. Return semantics are as specified by Field.compare
func (IntField) MarshalBinary ¶
MarshalBinary implement encoding.BinaryMarshaler
func (*IntField) UnmarshalBinary ¶
UnmarshalBinary implement encoding.BinaryUnmarshaler
type Iterator ¶
type Iterator interface { // Open opens the iterator. This must be called before any of the other methods. Open() error // Close Closes the iterator. When the iterator is closed, calling next(), hasNext(), or rewind() should return error Close() // HasNext Returns true if the iterator has more tuples. HasNext() bool // Next Returns the next tuple from the operator (typically implementing by reading // from a child operator or an access method). Next() *Tuple // Rewind Resets the iterator to the start. Rewind() error // Error return err Error() error }
Iterator iterator
type OpIterator ¶
type OpIterator interface { Iterator // TupleDesc Returns the TupleDesc associated with this OpIterator. TupleDesc() *TupleDesc }
OpIterator operation iterator interface
type Page ¶
type Page interface { encoding.BinaryMarshaler // PageID get the PageID PageID() PageID // MarkDirty mark the page dirty // if TxID is nil, Mark not dirty MarkDirty(*TxID) TupleDesc() *TupleDesc }
Page page
type Permission ¶
type Permission int
Permission perm
const ( // PermReadOnly 0 PermReadOnly Permission = iota // PermReadWrite 1 PermReadWrite )
func (Permission) String ¶
func (p Permission) String() (ret string)
type Predicate ¶
Predicate compares tuples to a specified Field value
type RecordID ¶
RecordID record id: PageID + TupleNum
func NewRecordID ¶
NewRecordID NewRecordID Pointer
type SeqScan ¶
type SeqScan struct { TxID *TxID TableID string TableAlias string DBFile DBFile Iter DbFileIterator Err error }
SeqScan sequence scan
func NewSeqScan ¶
NewSeqScan new SeqScan
type Tuple ¶
Tuple one record
Marshal format field-val1 | field-val2 |...
func (Tuple) MarshalBinary ¶
MarshalBinary marshal tuple
type TupleDesc ¶
type TupleDesc struct {
TdItems []TdItem
}
TupleDesc the tuple descrition
func NewTupleDesc ¶
NewTupleDesc create one TupleDesc
type TupleIterator ¶
type TupleIterator struct { Tuples []*Tuple TD *TupleDesc Err error // contains filtered or unexported fields }
TupleIterator Implements a OpIterator
func NewTupleIterator ¶
func NewTupleIterator(td *TupleDesc, tuples []*Tuple) *TupleIterator
NewTupleIterator new TupleIterator
func (*TupleIterator) Next ¶
func (it *TupleIterator) Next() (ret *Tuple)
Next next tuple; before call Next, should call HasNext