agnostic

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultSchema = "public"
)

Variables

View Source
var (
	NotImplemented = errors.New("not implemented")
)

Functions

func PrintQueryPlan

func PrintQueryPlan(n Node, depth int, printer func(fmt string, varargs ...any))

PrintQueryPlan

func ToInstance

func ToInstance(value, typeName string) (any, error)

func WithAlias

func WithAlias(alias string) func(*AttributeSelector)

Types

type AndPredicate

type AndPredicate struct {
	// contains filtered or unexported fields
}

func NewAndPredicate

func NewAndPredicate(left, right Predicate) *AndPredicate

func (*AndPredicate) Attribute

func (p *AndPredicate) Attribute() []string

func (*AndPredicate) Eval

func (p *AndPredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*AndPredicate) Left

func (p *AndPredicate) Left() (Predicate, bool)

func (*AndPredicate) Relation

func (p *AndPredicate) Relation() string

func (*AndPredicate) Right

func (p *AndPredicate) Right() (Predicate, bool)

func (AndPredicate) String

func (p AndPredicate) String() string

func (*AndPredicate) Type

func (p *AndPredicate) Type() PredicateType

type Attribute

type Attribute struct {
	// contains filtered or unexported fields
}

Attribute is a named column of a relation AKA Field AKA Column

func NewAttribute

func NewAttribute(name, typeName string) Attribute

func (Attribute) HasAutoIncrement

func (a Attribute) HasAutoIncrement() bool

func (Attribute) Name

func (a Attribute) Name() string

func (Attribute) String

func (a Attribute) String() string

func (Attribute) WithAutoIncrement

func (a Attribute) WithAutoIncrement() Attribute

func (Attribute) WithDefault

func (a Attribute) WithDefault(defaultValue Defaulter) Attribute

func (Attribute) WithDefaultConst

func (a Attribute) WithDefaultConst(defaultValue any) Attribute

func (Attribute) WithDefaultNow

func (a Attribute) WithDefaultNow() Attribute

func (Attribute) WithUnique

func (a Attribute) WithUnique() Attribute

type AttributeSelector

type AttributeSelector struct {
	// contains filtered or unexported fields
}

func NewAttributeSelector

func NewAttributeSelector(rel string, attrs []string, functors ...func(*AttributeSelector)) *AttributeSelector

func (*AttributeSelector) Alias

func (s *AttributeSelector) Alias() string

func (*AttributeSelector) Attribute

func (s *AttributeSelector) Attribute() []string

func (*AttributeSelector) Relation

func (s *AttributeSelector) Relation() string

func (*AttributeSelector) Select

func (s *AttributeSelector) Select(cols []string, in []*list.Element) (out []*Tuple, err error)

func (AttributeSelector) String

func (s AttributeSelector) String() string

type AttributeValueFunctor

type AttributeValueFunctor struct {
	// contains filtered or unexported fields
}

func (*AttributeValueFunctor) Attribute

func (f *AttributeValueFunctor) Attribute() []string

func (*AttributeValueFunctor) Relation

func (f *AttributeValueFunctor) Relation() string

func (AttributeValueFunctor) String

func (f AttributeValueFunctor) String() string

func (*AttributeValueFunctor) Value

func (f *AttributeValueFunctor) Value(cols []string, t *Tuple) any

type AvgSelector

type AvgSelector struct {
}

type ConstValueFunctor

type ConstValueFunctor struct {
	// contains filtered or unexported fields
}

func (*ConstValueFunctor) Attribute

func (f *ConstValueFunctor) Attribute() []string

func (*ConstValueFunctor) Relation

func (f *ConstValueFunctor) Relation() string

func (ConstValueFunctor) String

func (f ConstValueFunctor) String() string

func (*ConstValueFunctor) Value

func (f *ConstValueFunctor) Value([]string, *Tuple) any

type CountSelector

type CountSelector struct {
	// contains filtered or unexported fields
}

func NewCountSelector

func NewCountSelector(rname string, attr string) *CountSelector

func (*CountSelector) Alias

func (s *CountSelector) Alias() string

func (*CountSelector) Attribute

func (s *CountSelector) Attribute() []string

func (*CountSelector) Relation

func (s *CountSelector) Relation() string

func (*CountSelector) Select

func (s *CountSelector) Select(cols []string, in []*list.Element) (out []*Tuple, err error)

type Defaulter

type Defaulter func() any

func NewRandString

func NewRandString(n int) Defaulter

type Deleter

type Deleter struct {
	// contains filtered or unexported fields
}

func NewDeleterNode

func NewDeleterNode(relation *Relation, changes *list.List) *Deleter

func (*Deleter) Attribute

func (u *Deleter) Attribute() []string

func (*Deleter) Children

func (u *Deleter) Children() []Node

func (*Deleter) EstimateCardinal

func (u *Deleter) EstimateCardinal() int64

func (*Deleter) Exec

func (u *Deleter) Exec() (cols []string, out []*list.Element, err error)

func (*Deleter) Relation

func (u *Deleter) Relation() string

func (Deleter) String

func (u Deleter) String() string

type DistinctSorter

type DistinctSorter struct {
	// contains filtered or unexported fields
}

func NewDistinctSorter

func NewDistinctSorter(rel string, attrs []string) *DistinctSorter

func (*DistinctSorter) Children

func (d *DistinctSorter) Children() []Node

func (*DistinctSorter) EstimateCardinal

func (d *DistinctSorter) EstimateCardinal() int64

func (*DistinctSorter) Exec

func (d *DistinctSorter) Exec() ([]string, []*list.Element, error)

func (*DistinctSorter) Priority

func (d *DistinctSorter) Priority() int

func (*DistinctSorter) SetNode

func (d *DistinctSorter) SetNode(n Node)

func (DistinctSorter) String

func (s DistinctSorter) String() string

type Domain

type Domain struct {
}

Domain is the set of allowable values for an Attribute.

type Engine

type Engine struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewEngine

func NewEngine() *Engine

func (*Engine) Begin

func (e *Engine) Begin() (*Transaction, error)

type EqPredicate

type EqPredicate struct {
	// contains filtered or unexported fields
}

func NewEqPredicate

func NewEqPredicate(left, right ValueFunctor) *EqPredicate

func (*EqPredicate) Attribute

func (p *EqPredicate) Attribute() []string

func (*EqPredicate) Eval

func (p *EqPredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*EqPredicate) Left

func (p *EqPredicate) Left() (Predicate, bool)

func (*EqPredicate) Relation

func (p *EqPredicate) Relation() string

func (*EqPredicate) Right

func (p *EqPredicate) Right() (Predicate, bool)

func (EqPredicate) String

func (p EqPredicate) String() string

func (*EqPredicate) Type

func (p *EqPredicate) Type() PredicateType

type FalsePredicate

type FalsePredicate struct {
}

func NewFalsePredicate

func NewFalsePredicate() *FalsePredicate

func (*FalsePredicate) Attribute

func (p *FalsePredicate) Attribute() []string

func (*FalsePredicate) Eval

func (p *FalsePredicate) Eval([]string, *Tuple) (bool, error)

func (*FalsePredicate) Left

func (p *FalsePredicate) Left() (Predicate, bool)

func (*FalsePredicate) Relation

func (p *FalsePredicate) Relation() string

func (*FalsePredicate) Right

func (p *FalsePredicate) Right() (Predicate, bool)

func (FalsePredicate) String

func (p FalsePredicate) String() string

func (*FalsePredicate) Type

func (p *FalsePredicate) Type() PredicateType

type ForeignKey

type ForeignKey struct {
	// contains filtered or unexported fields
}

type GePredicate

type GePredicate struct {
	// contains filtered or unexported fields
}

func NewGePredicate

func NewGePredicate(left, right ValueFunctor) *GePredicate

func (*GePredicate) Attribute

func (p *GePredicate) Attribute() []string

func (*GePredicate) Eval

func (p *GePredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*GePredicate) Left

func (p *GePredicate) Left() (Predicate, bool)

func (*GePredicate) Relation

func (p *GePredicate) Relation() string

func (*GePredicate) Right

func (p *GePredicate) Right() (Predicate, bool)

func (GePredicate) String

func (p GePredicate) String() string

func (*GePredicate) Type

func (p *GePredicate) Type() PredicateType

type GeqPredicate

type GeqPredicate struct {
	// contains filtered or unexported fields
}

func NewGeqPredicate

func NewGeqPredicate(left, right ValueFunctor) *GeqPredicate

func (*GeqPredicate) Attribute

func (p *GeqPredicate) Attribute() []string

func (*GeqPredicate) Eval

func (p *GeqPredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*GeqPredicate) Left

func (p *GeqPredicate) Left() (Predicate, bool)

func (*GeqPredicate) Relation

func (p *GeqPredicate) Relation() string

func (*GeqPredicate) Right

func (p *GeqPredicate) Right() (Predicate, bool)

func (GeqPredicate) String

func (p GeqPredicate) String() string

func (*GeqPredicate) Type

func (p *GeqPredicate) Type() PredicateType

type GroupBySorter

type GroupBySorter struct {
	// contains filtered or unexported fields
}

func NewGroupBySorter

func NewGroupBySorter(rel string, attrs []string) *GroupBySorter

func (*GroupBySorter) Children

func (s *GroupBySorter) Children() []Node

func (*GroupBySorter) EstimateCardinal

func (s *GroupBySorter) EstimateCardinal() int64

func (*GroupBySorter) Exec

func (s *GroupBySorter) Exec() ([]string, []*list.Element, error)

func (*GroupBySorter) Priority

func (s *GroupBySorter) Priority() int

func (*GroupBySorter) SetNode

func (s *GroupBySorter) SetNode(n Node)

func (*GroupBySorter) SetSelector

func (s *GroupBySorter) SetSelector(n Node)

func (GroupBySorter) String

func (s GroupBySorter) String() string

type HashIndex

type HashIndex struct {
	maphash.Hash
	// contains filtered or unexported fields
}

func NewHashIndex

func NewHashIndex(name string, relName string, relAttrs []Attribute, attrsName []string, attrs []int) *HashIndex

func (*HashIndex) Add

func (h *HashIndex) Add(e *list.Element)

func (*HashIndex) CanSourceWith

func (h *HashIndex) CanSourceWith(p Predicate) (bool, int64)

func (*HashIndex) Get

func (h *HashIndex) Get(values []any) (*list.Element, error)

func (*HashIndex) Name

func (h *HashIndex) Name() string

func (*HashIndex) Remove

func (h *HashIndex) Remove(e *list.Element)

func (*HashIndex) String

func (h *HashIndex) String() string

func (*HashIndex) Truncate

func (h *HashIndex) Truncate()

type InPredicate

type InPredicate struct {
	// contains filtered or unexported fields
}

func NewInPredicate

func NewInPredicate(v ValueFunctor, src Node) *InPredicate

func (*InPredicate) Attribute

func (p *InPredicate) Attribute() []string

func (*InPredicate) Eval

func (p *InPredicate) Eval(inCols []string, in *Tuple) (bool, error)

func (*InPredicate) Left

func (p *InPredicate) Left() (Predicate, bool)

func (*InPredicate) Relation

func (p *InPredicate) Relation() string

func (*InPredicate) Right

func (p *InPredicate) Right() (Predicate, bool)

func (InPredicate) String

func (p InPredicate) String() string

func (*InPredicate) Type

func (p *InPredicate) Type() PredicateType

type Index

type Index interface {
	Truncate()
	Add(*list.Element)
	Remove(*list.Element)
	Name() string
	CanSourceWith(p Predicate) (bool, int64)
	Get(values []any) (*list.Element, error)
}

type IndexSrc

type IndexSrc struct {
	// contains filtered or unexported fields
}

func NewHashIndexSource

func NewHashIndexSource(index Index, alias string, p Predicate) (*IndexSrc, error)

func (*IndexSrc) Columns

func (s *IndexSrc) Columns() []string

func (*IndexSrc) EstimateCardinal

func (s *IndexSrc) EstimateCardinal() int64

func (*IndexSrc) HasNext

func (s *IndexSrc) HasNext() bool

func (*IndexSrc) Next

func (s *IndexSrc) Next() *list.Element

func (IndexSrc) String

func (s IndexSrc) String() string

type IndexType

type IndexType int
const (
	HashIndexType IndexType = iota
	BTreeIndexType
)

type Joiner

type Joiner interface {
	Node
	Left() string
	SetLeft(n Node)
	Right() string
	SetRight(n Node)
}

Joiner joins two relation together.

Should be able to estimate cardinality of join for cost optimization.

Possible implementations:

  • NaturalJoiner
  • LeftOuterJoiner
  • RightOuterJoiner
  • FullOuterJoiner

type Joiners

type Joiners []Joiner

func (Joiners) Len

func (js Joiners) Len() int

func (Joiners) Less

func (js Joiners) Less(i, j int) bool

func (Joiners) Swap

func (js Joiners) Swap(i, j int)

type LePredicate

type LePredicate struct {
	// contains filtered or unexported fields
}

func NewLePredicate

func NewLePredicate(left, right ValueFunctor) *LePredicate

func (*LePredicate) Attribute

func (p *LePredicate) Attribute() []string

func (*LePredicate) Eval

func (p *LePredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*LePredicate) Left

func (p *LePredicate) Left() (Predicate, bool)

func (*LePredicate) Relation

func (p *LePredicate) Relation() string

func (*LePredicate) Right

func (p *LePredicate) Right() (Predicate, bool)

func (LePredicate) String

func (p LePredicate) String() string

func (*LePredicate) Type

func (p *LePredicate) Type() PredicateType

type LeqPredicate

type LeqPredicate struct {
	// contains filtered or unexported fields
}

func NewLeqPredicate

func NewLeqPredicate(left, right ValueFunctor) *LeqPredicate

func (*LeqPredicate) Attribute

func (p *LeqPredicate) Attribute() []string

func (*LeqPredicate) Eval

func (p *LeqPredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*LeqPredicate) Left

func (p *LeqPredicate) Left() (Predicate, bool)

func (*LeqPredicate) Relation

func (p *LeqPredicate) Relation() string

func (*LeqPredicate) Right

func (p *LeqPredicate) Right() (Predicate, bool)

func (LeqPredicate) String

func (p LeqPredicate) String() string

func (*LeqPredicate) Type

func (p *LeqPredicate) Type() PredicateType

type LimitSorter

type LimitSorter struct {
	// contains filtered or unexported fields
}

func NewLimitSorter

func NewLimitSorter(limit int64) *LimitSorter

func (*LimitSorter) Children

func (d *LimitSorter) Children() []Node

func (*LimitSorter) EstimateCardinal

func (d *LimitSorter) EstimateCardinal() int64

func (*LimitSorter) Exec

func (d *LimitSorter) Exec() ([]string, []*list.Element, error)

func (*LimitSorter) Priority

func (d *LimitSorter) Priority() int

func (*LimitSorter) SetNode

func (d *LimitSorter) SetNode(n Node)

func (LimitSorter) String

func (s LimitSorter) String() string

type ListNode

type ListNode struct {
	// contains filtered or unexported fields
}

func NewListNode

func NewListNode(values ...any) *ListNode

func (*ListNode) Children

func (ln *ListNode) Children() []Node

func (*ListNode) EstimateCardinal

func (ln *ListNode) EstimateCardinal() int64

func (*ListNode) Exec

func (ln *ListNode) Exec() ([]string, []*list.Element, error)

func (ListNode) String

func (ln ListNode) String() string

type MaxSelector

type MaxSelector struct {
}

type NaturalJoin

type NaturalJoin struct {
	// contains filtered or unexported fields
}

func NewNaturalJoin

func NewNaturalJoin(leftRel, leftAttr, rightRel, rightAttr string) *NaturalJoin

func (*NaturalJoin) Children

func (j *NaturalJoin) Children() []Node

func (*NaturalJoin) EstimateCardinal

func (j *NaturalJoin) EstimateCardinal() int64

func (*NaturalJoin) Exec

func (j *NaturalJoin) Exec() ([]string, []*list.Element, error)

func (*NaturalJoin) Left

func (j *NaturalJoin) Left() string

func (*NaturalJoin) Right

func (j *NaturalJoin) Right() string

func (*NaturalJoin) SetLeft

func (j *NaturalJoin) SetLeft(n Node)

func (*NaturalJoin) SetRight

func (j *NaturalJoin) SetRight(n Node)

func (NaturalJoin) String

func (j NaturalJoin) String() string

type NeqPredicate

type NeqPredicate struct {
	// contains filtered or unexported fields
}

func NewNeqPredicate

func NewNeqPredicate(left, right ValueFunctor) *NeqPredicate

func (*NeqPredicate) Attribute

func (p *NeqPredicate) Attribute() []string

func (*NeqPredicate) Eval

func (p *NeqPredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*NeqPredicate) Left

func (p *NeqPredicate) Left() (Predicate, bool)

func (*NeqPredicate) Relation

func (p *NeqPredicate) Relation() string

func (*NeqPredicate) Right

func (p *NeqPredicate) Right() (Predicate, bool)

func (NeqPredicate) String

func (p NeqPredicate) String() string

func (*NeqPredicate) Type

func (p *NeqPredicate) Type() PredicateType

type Node

type Node interface {
	Exec() ([]string, []*list.Element, error)
	EstimateCardinal() int64
	Children() []Node
}

Node is an element of a quey plan

Joiner, Sorter and Scanner implement Node.

type NotPredicate

type NotPredicate struct {
	// contains filtered or unexported fields
}

func NewNotPredicate

func NewNotPredicate(src Predicate) *NotPredicate

func (*NotPredicate) Attribute

func (p *NotPredicate) Attribute() []string

func (*NotPredicate) Eval

func (p *NotPredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*NotPredicate) Left

func (p *NotPredicate) Left() (Predicate, bool)

func (*NotPredicate) Relation

func (p *NotPredicate) Relation() string

func (*NotPredicate) Right

func (p *NotPredicate) Right() (Predicate, bool)

func (NotPredicate) String

func (p NotPredicate) String() string

func (*NotPredicate) Type

func (p *NotPredicate) Type() PredicateType

type NowValueFunctor

type NowValueFunctor struct {
}

func (*NowValueFunctor) Attribute

func (f *NowValueFunctor) Attribute() []string

func (*NowValueFunctor) Relation

func (f *NowValueFunctor) Relation() string

func (NowValueFunctor) String

func (f NowValueFunctor) String() string

func (*NowValueFunctor) Value

func (f *NowValueFunctor) Value([]string, *Tuple) any

type OffsetSorter

type OffsetSorter struct {
	// contains filtered or unexported fields
}

func NewOffsetSorter

func NewOffsetSorter(o int) *OffsetSorter

func (*OffsetSorter) Children

func (s *OffsetSorter) Children() []Node

func (*OffsetSorter) EstimateCardinal

func (s *OffsetSorter) EstimateCardinal() int64

func (*OffsetSorter) Exec

func (s *OffsetSorter) Exec() ([]string, []*list.Element, error)

func (*OffsetSorter) Priority

func (s *OffsetSorter) Priority() int

func (*OffsetSorter) SetNode

func (s *OffsetSorter) SetNode(n Node)

func (OffsetSorter) String

func (s OffsetSorter) String() string

type OrPredicate

type OrPredicate struct {
	// contains filtered or unexported fields
}

func NewOrPredicate

func NewOrPredicate(left, right Predicate) *OrPredicate

func (*OrPredicate) Attribute

func (p *OrPredicate) Attribute() []string

func (*OrPredicate) Eval

func (p *OrPredicate) Eval(cols []string, t *Tuple) (bool, error)

func (*OrPredicate) Left

func (p *OrPredicate) Left() (Predicate, bool)

func (*OrPredicate) Relation

func (p *OrPredicate) Relation() string

func (*OrPredicate) Right

func (p *OrPredicate) Right() (Predicate, bool)

func (OrPredicate) String

func (p OrPredicate) String() string

func (*OrPredicate) Type

func (p *OrPredicate) Type() PredicateType

type OrderBySorter

type OrderBySorter struct {
	// contains filtered or unexported fields
}

func NewOrderBySorter

func NewOrderBySorter(rel string, attrs []SortExpression) *OrderBySorter

func (*OrderBySorter) Children

func (s *OrderBySorter) Children() []Node

func (*OrderBySorter) EstimateCardinal

func (s *OrderBySorter) EstimateCardinal() int64

func (*OrderBySorter) Exec

func (s *OrderBySorter) Exec() ([]string, []*list.Element, error)

func (*OrderBySorter) Priority

func (s *OrderBySorter) Priority() int

func (*OrderBySorter) SetNode

func (s *OrderBySorter) SetNode(n Node)

func (OrderBySorter) String

func (s OrderBySorter) String() string

type Picker

type Picker interface {
	Relation() string
	Attribute() []string
}

Picker interface is used by query planner to define which relations and attributes are used in a query.

Can be empty.

Selector and Predicate implement Picker.

type Predicate

type Predicate interface {
	Picker
	Type() PredicateType
	Left() (Predicate, bool)
	Right() (Predicate, bool)
	Eval([]string, *Tuple) (bool, error)
}

Predicate defines filter to be applied on spcified relation row

func NewComparisonPredicate

func NewComparisonPredicate(left ValueFunctor, t PredicateType, right ValueFunctor) (Predicate, error)

type PredicateType

type PredicateType int
const (
	And PredicateType = iota
	Or
	Eq
	Geq
	Leq
	Le
	Ge
	Neq
	Like
	In
	Not
	True
	False
)

type Relation

type Relation struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewRelation

func NewRelation(schema, name string, attributes []Attribute, pk []string) (*Relation, error)

func (*Relation) Attribute

func (r *Relation) Attribute(name string) (int, Attribute, error)

func (*Relation) CheckPrimaryKey added in v0.1.3

func (r *Relation) CheckPrimaryKey(tuple *Tuple) (bool, error)

func (Relation) String

func (r Relation) String() string

func (*Relation) Truncate

func (r *Relation) Truncate() int64

type RelationChange

type RelationChange struct {
	// contains filtered or unexported fields
}

type RelationScanner

type RelationScanner struct {
	// contains filtered or unexported fields
}

func NewRelationScanner

func NewRelationScanner(src Source, predicates []Predicate) *RelationScanner

func (*RelationScanner) Append

func (s *RelationScanner) Append(p Predicate)

func (*RelationScanner) Children

func (s *RelationScanner) Children() []Node

func (*RelationScanner) EstimateCardinal

func (s *RelationScanner) EstimateCardinal() int64

No idea on how to estimate cardinal of scanner given predicates

min: 0 max: len(src) avg: len(src)/2

func (*RelationScanner) Exec

func (s *RelationScanner) Exec() ([]string, []*list.Element, error)

func (RelationScanner) String

func (s RelationScanner) String() string

type Scanner

type Scanner interface {
	Node
	Append(Predicate)
}

Scanner produce results by scanning the relation.

The query plan initialize a Scanner for each relation with: * The best source possible regarding cost (Hashmap, Btree, SeqScan) * A (possibly) recursive predicate to filter on

type Schema

type Schema struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSchema

func NewSchema(name string) *Schema

func (*Schema) Add

func (s *Schema) Add(name string, r *Relation)

func (*Schema) Relation

func (s *Schema) Relation(name string) (*Relation, error)

func (*Schema) Remove

func (s *Schema) Remove(name string) (*Relation, error)

type SchemaChange

type SchemaChange struct {
	// contains filtered or unexported fields
}

type Selector

type Selector interface {
	Picker
	Alias() string
	Select([]string, []*list.Element) ([]*Tuple, error)
}

Selector defines values to be returned to user

Possible Selector implementations:

  • Attribute
  • Star
  • Max
  • Min
  • Avg
  • ...

type SelectorNode

type SelectorNode struct {
	// contains filtered or unexported fields
}

func NewSelectorNode

func NewSelectorNode(selectors []Selector, n Node) *SelectorNode

func (*SelectorNode) Children

func (sn *SelectorNode) Children() []Node

func (*SelectorNode) Columns

func (sn *SelectorNode) Columns() []string

func (*SelectorNode) EstimateCardinal

func (sn *SelectorNode) EstimateCardinal() int64

func (*SelectorNode) Exec

func (sn *SelectorNode) Exec() ([]string, []*list.Element, error)

func (SelectorNode) String

func (sn SelectorNode) String() string

type SeqScanSrc

type SeqScanSrc struct {
	// contains filtered or unexported fields
}

func NewSeqScan

func NewSeqScan(r *Relation, alias string) *SeqScanSrc

func (*SeqScanSrc) Columns

func (s *SeqScanSrc) Columns() []string

func (*SeqScanSrc) EstimateCardinal

func (s *SeqScanSrc) EstimateCardinal() int64

func (*SeqScanSrc) HasNext

func (s *SeqScanSrc) HasNext() bool

func (*SeqScanSrc) Next

func (s *SeqScanSrc) Next() *list.Element

func (SeqScanSrc) String

func (s SeqScanSrc) String() string

type SortExpression

type SortExpression struct {
	// contains filtered or unexported fields
}

func NewSortExpression

func NewSortExpression(attr string, direction SortType) SortExpression

type SortType

type SortType int
const (
	ASC SortType = iota
	DESC
)

type Sorter

type Sorter interface {
	Node
	Priority() int
	SetNode(Node)
}

Sorter produce a sorted result from single child node

GroupBy (-10000) before Having (-5000) before Order (0) before Distinct (1000) before Offset (5000) before Limit (10000).

GroupBy must contains both selector node and last join to compute arithmetic on all groups

Possible implementations:

  • OrderAscSort
  • OrderDescSort
  • HavingSort
  • DistinctSort
  • Limit
  • Offset

type Sorters

type Sorters []Sorter

Sorters sort the sorters \o/

Why ? I don't want to put on package caller the responsability to order them correctly. It's up to the query planner.

func (Sorters) Len

func (js Sorters) Len() int

func (Sorters) Less

func (js Sorters) Less(i, j int) bool

func (Sorters) Swap

func (js Sorters) Swap(i, j int)

type Source

type Source interface {
	HasNext() bool
	Next() *list.Element
	EstimateCardinal() int64
	Columns() []string
}

type StarSelector

type StarSelector struct {
	// contains filtered or unexported fields
}

func NewStarSelector

func NewStarSelector(rname string) *StarSelector

func (*StarSelector) Alias

func (s *StarSelector) Alias() string

func (*StarSelector) Attribute

func (s *StarSelector) Attribute() []string

func (*StarSelector) Relation

func (s *StarSelector) Relation() string

func (*StarSelector) Select

func (s *StarSelector) Select(cols []string, in []*list.Element) (out []*Tuple, err error)

func (StarSelector) String

func (s StarSelector) String() string

type SubqueryNode

type SubqueryNode struct {
	// contains filtered or unexported fields
}

func NewSubqueryNode

func NewSubqueryNode(src Node) *SubqueryNode

func (*SubqueryNode) Children

func (sn *SubqueryNode) Children() []Node

func (*SubqueryNode) EstimateCardinal

func (sn *SubqueryNode) EstimateCardinal() int64

func (*SubqueryNode) Exec

func (sn *SubqueryNode) Exec() ([]string, []*list.Element, error)

func (SubqueryNode) String

func (sn SubqueryNode) String() string

type Transaction

type Transaction struct {
	// contains filtered or unexported fields
}

func NewTransaction

func NewTransaction(e *Engine) (*Transaction, error)

func (*Transaction) CheckRelation

func (t *Transaction) CheckRelation(schemaName, relName string) bool

func (*Transaction) CheckSchema

func (t *Transaction) CheckSchema(schemaName string) bool

func (*Transaction) Commit

func (t *Transaction) Commit() (int, error)

func (*Transaction) CreateIndex

func (t *Transaction) CreateIndex(schema, relation, index string, it IndexType, attrs []string) error

func (*Transaction) CreateRelation

func (t *Transaction) CreateRelation(schemaName, relName string, attributes []Attribute, pk []string) error

func (*Transaction) CreateSchema

func (t *Transaction) CreateSchema(schemaName string) error

func (*Transaction) Delete

func (t *Transaction) Delete(schema, relation string, selectors []Selector, p Predicate) ([]string, []*Tuple, error)

Delete rows from relation.

Delete node needs to be inserted right as child of selector node.

func (*Transaction) DropRelation

func (t *Transaction) DropRelation(schemaName, relName string) error

func (*Transaction) DropSchema

func (t *Transaction) DropSchema(schemaName string) error

func (Transaction) Error

func (t Transaction) Error() error

func (*Transaction) Insert

func (t *Transaction) Insert(schema, relation string, values map[string]any) (*Tuple, error)

Build tuple for given relation for each column: - if not specified, use default value if set - if specified:

  • check domain
  • check unique
  • check foreign key

If tuple is valid, then - check primary key - insert into rows list - update index if any

func (*Transaction) Plan

func (t *Transaction) Plan(schema string, selectors []Selector, p Predicate, joiners []Joiner, sorters []Sorter) (Node, error)

func (*Transaction) Query

func (t *Transaction) Query(schema string, selectors []Selector, p Predicate, joiners []Joiner, sorters []Sorter) ([]string, []*Tuple, error)

Query data from relations

cf: https://en.wikipedia.org/wiki/Query_optimization

cf: https://en.wikipedia.org/wiki/Relational_algebra

* (1) Transaction safety : list all touched relations and lock them * (2) Sourcing : evaluate which indexes query can use for each relation. HashIndex > Btree > SeqScan * (3) Join ordering : estimate the cardinality (Join selection factor) of each relation after predicates filtering, then order the join by lower cardinality * (4) Selection : build filtered relations on each leaf (parallelisation possible) * (5) Join : join filtered relations on each node recursively * (6) Return result : return result to user with selectors

TODO: foreign keys should have hashmap index

func (*Transaction) RelationAttribute

func (t *Transaction) RelationAttribute(schName, relName, attrName string) (int, Attribute, error)

func (*Transaction) Rollback

func (t *Transaction) Rollback()

func (*Transaction) Truncate

func (t *Transaction) Truncate(schema, relation string) (int64, error)

func (*Transaction) Update

func (t *Transaction) Update(schema, relation string, values map[string]any, selectors []Selector, p Predicate) ([]string, []*Tuple, error)

Update relation with given values.

Update node needs to be inserted right as child of selector node.

type TruePredicate

type TruePredicate struct {
}

func NewTruePredicate

func NewTruePredicate() *TruePredicate

func (*TruePredicate) Attribute

func (p *TruePredicate) Attribute() []string

func (*TruePredicate) Eval

func (p *TruePredicate) Eval([]string, *Tuple) (bool, error)

func (*TruePredicate) Left

func (p *TruePredicate) Left() (Predicate, bool)

func (*TruePredicate) Relation

func (p *TruePredicate) Relation() string

func (*TruePredicate) Right

func (p *TruePredicate) Right() (Predicate, bool)

func (TruePredicate) String

func (p TruePredicate) String() string

func (*TruePredicate) Type

func (p *TruePredicate) Type() PredicateType

type Tuple

type Tuple struct {
	// contains filtered or unexported fields
}

Tuple is a row in a relation

func NewTuple

func NewTuple(values ...any) *Tuple

NewTuple should check that value are for the right Attribute and match domain

func (*Tuple) Append

func (t *Tuple) Append(values ...any)

Append add a value to the tuple

func (*Tuple) Values

func (t *Tuple) Values() []any

type Updater

type Updater struct {
	// contains filtered or unexported fields
}

func NewUpdaterNode

func NewUpdaterNode(relation *Relation, changes *list.List, values map[string]any) *Updater

func (*Updater) Attribute

func (u *Updater) Attribute() []string

func (*Updater) Children

func (u *Updater) Children() []Node

func (*Updater) EstimateCardinal

func (u *Updater) EstimateCardinal() int64

func (*Updater) Exec

func (u *Updater) Exec() (cols []string, out []*list.Element, err error)

func (*Updater) Relation

func (u *Updater) Relation() string

func (Updater) String

func (u Updater) String() string

type ValueChange

type ValueChange struct {
	// contains filtered or unexported fields
}

type ValueFunctor

type ValueFunctor interface {
	Picker
	Value(columns []string, tuple *Tuple) any
}

ValueFunctor is used by Predicate to compare values

Possible ValueFunctor implementation:

  • ConstValueFunctor
  • AttributeValueFunctor
  • NowValueFunctor

func NewAttributeValueFunctor

func NewAttributeValueFunctor(rname, aname string) ValueFunctor

NewAttributeValueFunctor creates a ValueFunctor returning attribute value in given tuple

func NewConstValueFunctor

func NewConstValueFunctor(v any) ValueFunctor

NewConstValueFunctor creates a ValueFunctor returning v

func NewNowValueFunctor

func NewNowValueFunctor() ValueFunctor

NewNowValueFunctor creates a ValueFunctor returning time.Now()

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL