Documentation
¶
Overview ¶
KV provides a set of key value operations that implement data structures such as a b-tree to efficiently access the page cache. KV implements an abstraction called a cursor to efficiently seek and scan the btree. Each B tree is referenced with a page number assigned by the catalog.
Index ¶
- func Decode(v []byte) ([]any, error)
- func DecodeKey(v []byte) (any, error)
- func Encode(v []interface{}) ([]byte, error)
- func EncodeKey(v any) ([]byte, error)
- type Cursor
- func (c *Cursor) Count() int
- func (c *Cursor) DeleteCurrent()
- func (c *Cursor) Exists(key []byte) bool
- func (c *Cursor) Get(key []byte) ([]byte, bool)
- func (c *Cursor) GetKey() []byte
- func (c *Cursor) GetValue() []byte
- func (c *Cursor) GotoFirstRecord() bool
- func (c *Cursor) GotoKey(key []byte) bool
- func (c *Cursor) GotoLastRecord() bool
- func (c *Cursor) GotoNext() bool
- func (c *Cursor) NewRowID() int
- func (c *Cursor) Set(key, value []byte)
- type KV
- func (kv *KV) BeginReadTransaction() error
- func (kv *KV) BeginWriteTransaction() error
- func (kv *KV) EndReadTransaction()
- func (kv *KV) EndWriteTransaction() error
- func (kv *KV) GetCatalog() *catalog.Catalog
- func (kv *KV) NewBTree() int
- func (kv *KV) NewCursor(rootPageNumber int) *Cursor
- func (kv *KV) ParseSchema() error
- func (kv *KV) RollbackWrite()
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Cursor ¶
type Cursor struct {
// contains filtered or unexported fields
}
Cursor is an abstraction that can seek and scan ranges of a btree.
func (*Cursor) Count ¶
Count returns the count of the current b trees leaf node entries.
Count does this not by scanning each individual tuple, but scanning each page and summing the computed counter on the page.
func (*Cursor) DeleteCurrent ¶
func (c *Cursor) DeleteCurrent()
DeleteCurrent deletes the current tuple the cursor is pointing to. This leaves the cursor pointing at the next tuple in which case calling GotoNext will be a no-op. If the next tuple is the end of the table GotoNext will also be aware of this. This is all to facilitate execution plans which delete in a loop.
func (*Cursor) Exists ¶
Exists will probe the specified key and return true or false if the key exists or not.
func (*Cursor) Get ¶
Get returns a byte array corresponding to the key and a bool indicating if the key was found. The pageNumber has to do with the root page of the corresponding table. The system catalog uses the page number 1.
func (*Cursor) GotoFirstRecord ¶
GotoFirstRecord moves the cursor to the first tuple in ascending order. It returns true if the table has values. It returns false if the table is empty.
func (*Cursor) GotoLastRecord ¶
GotoLastRecord moves the cursor to the last tuple in the last page (descending ordering). It returns true if the table has values otherwise false.
func (*Cursor) GotoNext ¶
GotoNext moves the cursor to the next tuple in ascending order. If there is no next tuple this function will return false otherwise it will return true.
GotoNext may have special behavior if a DeleteCurrent has been previously invoked. GotoNext will essentially be a noop that makes the illusion it did the job that was already done by DeleteCurrent.
type KV ¶
type KV struct {
// contains filtered or unexported fields
}
KV is an abstraction on the pager module that provides efficient reads and writes through b tree indexes.
func (*KV) BeginReadTransaction ¶
BeginReadTransaction begins a read transaction.
func (*KV) BeginWriteTransaction ¶
BeginWriteTransaction begins a write transaction.
func (*KV) EndReadTransaction ¶
func (kv *KV) EndReadTransaction()
EndReadTransaction ends a read transaction.
func (*KV) EndWriteTransaction ¶
EndWriteTransaction ends a write transaction.
func (*KV) GetCatalog ¶
GetCatalog returns and instance of the system catalog.
func (*KV) ParseSchema ¶
ParseSchema updates the system catalog by reading the schema table.
func (*KV) RollbackWrite ¶
func (kv *KV) RollbackWrite()
RollbackWrite rolls back and ends a write transaction.