Documentation ¶
Index ¶
- Constants
- Variables
- func PrintQueryPlan(n Node, depth int, printer func(fmt string, varargs ...any))
- func ToInstance(value, typeName string) (any, error)
- func WithAlias(alias string) func(*AttributeSelector)
- type AndPredicate
- func (p *AndPredicate) Attribute() []string
- func (p *AndPredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *AndPredicate) Left() (Predicate, bool)
- func (p *AndPredicate) Relation() string
- func (p *AndPredicate) Right() (Predicate, bool)
- func (p AndPredicate) String() string
- func (p *AndPredicate) Type() PredicateType
- type Attribute
- func (a Attribute) HasAutoIncrement() bool
- func (a Attribute) Name() string
- func (a Attribute) String() string
- func (a Attribute) WithAutoIncrement() Attribute
- func (a Attribute) WithDefault(defaultValue Defaulter) Attribute
- func (a Attribute) WithDefaultConst(defaultValue any) Attribute
- func (a Attribute) WithDefaultNow() Attribute
- func (a Attribute) WithUnique() Attribute
- type AttributeSelector
- type AttributeValueFunctor
- type AvgSelector
- type ConstValueFunctor
- type CountSelector
- type Defaulter
- type Deleter
- type DistinctSorter
- type Domain
- type Engine
- type EqPredicate
- func (p *EqPredicate) Attribute() []string
- func (p *EqPredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *EqPredicate) Left() (Predicate, bool)
- func (p *EqPredicate) Relation() string
- func (p *EqPredicate) Right() (Predicate, bool)
- func (p EqPredicate) String() string
- func (p *EqPredicate) Type() PredicateType
- type FalsePredicate
- func (p *FalsePredicate) Attribute() []string
- func (p *FalsePredicate) Eval([]string, *Tuple) (bool, error)
- func (p *FalsePredicate) Left() (Predicate, bool)
- func (p *FalsePredicate) Relation() string
- func (p *FalsePredicate) Right() (Predicate, bool)
- func (p FalsePredicate) String() string
- func (p *FalsePredicate) Type() PredicateType
- type ForeignKey
- type GePredicate
- func (p *GePredicate) Attribute() []string
- func (p *GePredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *GePredicate) Left() (Predicate, bool)
- func (p *GePredicate) Relation() string
- func (p *GePredicate) Right() (Predicate, bool)
- func (p GePredicate) String() string
- func (p *GePredicate) Type() PredicateType
- type GeqPredicate
- func (p *GeqPredicate) Attribute() []string
- func (p *GeqPredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *GeqPredicate) Left() (Predicate, bool)
- func (p *GeqPredicate) Relation() string
- func (p *GeqPredicate) Right() (Predicate, bool)
- func (p GeqPredicate) String() string
- func (p *GeqPredicate) Type() PredicateType
- type GroupBySorter
- func (s *GroupBySorter) Children() []Node
- func (s *GroupBySorter) EstimateCardinal() int64
- func (s *GroupBySorter) Exec() ([]string, []*list.Element, error)
- func (s *GroupBySorter) Priority() int
- func (s *GroupBySorter) SetNode(n Node)
- func (s *GroupBySorter) SetSelector(n Node)
- func (s GroupBySorter) String() string
- type HashIndex
- func (h *HashIndex) Add(e *list.Element)
- func (h *HashIndex) CanSourceWith(p Predicate) (bool, int64)
- func (h *HashIndex) Get(values []any) (*list.Element, error)
- func (h *HashIndex) Name() string
- func (h *HashIndex) Remove(e *list.Element)
- func (h *HashIndex) String() string
- func (h *HashIndex) Truncate()
- type InPredicate
- func (p *InPredicate) Attribute() []string
- func (p *InPredicate) Eval(inCols []string, in *Tuple) (bool, error)
- func (p *InPredicate) Left() (Predicate, bool)
- func (p *InPredicate) Relation() string
- func (p *InPredicate) Right() (Predicate, bool)
- func (p InPredicate) String() string
- func (p *InPredicate) Type() PredicateType
- type Index
- type IndexSrc
- type IndexType
- type Joiner
- type Joiners
- type LePredicate
- func (p *LePredicate) Attribute() []string
- func (p *LePredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *LePredicate) Left() (Predicate, bool)
- func (p *LePredicate) Relation() string
- func (p *LePredicate) Right() (Predicate, bool)
- func (p LePredicate) String() string
- func (p *LePredicate) Type() PredicateType
- type LeqPredicate
- func (p *LeqPredicate) Attribute() []string
- func (p *LeqPredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *LeqPredicate) Left() (Predicate, bool)
- func (p *LeqPredicate) Relation() string
- func (p *LeqPredicate) Right() (Predicate, bool)
- func (p LeqPredicate) String() string
- func (p *LeqPredicate) Type() PredicateType
- type LimitSorter
- type ListNode
- type MaxSelector
- type NaturalJoin
- func (j *NaturalJoin) Children() []Node
- func (j *NaturalJoin) EstimateCardinal() int64
- func (j *NaturalJoin) Exec() ([]string, []*list.Element, error)
- func (j *NaturalJoin) Left() string
- func (j *NaturalJoin) Right() string
- func (j *NaturalJoin) SetLeft(n Node)
- func (j *NaturalJoin) SetRight(n Node)
- func (j NaturalJoin) String() string
- type NeqPredicate
- func (p *NeqPredicate) Attribute() []string
- func (p *NeqPredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *NeqPredicate) Left() (Predicate, bool)
- func (p *NeqPredicate) Relation() string
- func (p *NeqPredicate) Right() (Predicate, bool)
- func (p NeqPredicate) String() string
- func (p *NeqPredicate) Type() PredicateType
- type Node
- type NotPredicate
- func (p *NotPredicate) Attribute() []string
- func (p *NotPredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *NotPredicate) Left() (Predicate, bool)
- func (p *NotPredicate) Relation() string
- func (p *NotPredicate) Right() (Predicate, bool)
- func (p NotPredicate) String() string
- func (p *NotPredicate) Type() PredicateType
- type NowValueFunctor
- type OffsetSorter
- type OrPredicate
- func (p *OrPredicate) Attribute() []string
- func (p *OrPredicate) Eval(cols []string, t *Tuple) (bool, error)
- func (p *OrPredicate) Left() (Predicate, bool)
- func (p *OrPredicate) Relation() string
- func (p *OrPredicate) Right() (Predicate, bool)
- func (p OrPredicate) String() string
- func (p *OrPredicate) Type() PredicateType
- type OrderBySorter
- type Picker
- type Predicate
- type PredicateType
- type Relation
- type RelationChange
- type RelationScanner
- type Scanner
- type Schema
- type SchemaChange
- type Selector
- type SelectorNode
- type SeqScanSrc
- type SortExpression
- type SortType
- type Sorter
- type Sorters
- type Source
- type StarSelector
- type SubqueryNode
- type Transaction
- func (t *Transaction) CheckRelation(schemaName, relName string) bool
- func (t *Transaction) CheckSchema(schemaName string) bool
- func (t *Transaction) Commit() (int, error)
- func (t *Transaction) CreateIndex(schema, relation, index string, it IndexType, attrs []string) error
- func (t *Transaction) CreateRelation(schemaName, relName string, attributes []Attribute, pk []string) error
- func (t *Transaction) CreateSchema(schemaName string) error
- func (t *Transaction) Delete(schema, relation string, selectors []Selector, p Predicate) ([]string, []*Tuple, error)
- func (t *Transaction) DropRelation(schemaName, relName string) error
- func (t *Transaction) DropSchema(schemaName string) error
- func (t Transaction) Error() error
- func (t *Transaction) Insert(schema, relation string, values map[string]any) (*Tuple, error)
- func (t *Transaction) Plan(schema string, selectors []Selector, p Predicate, joiners []Joiner, ...) (Node, error)
- func (t *Transaction) Query(schema string, selectors []Selector, p Predicate, joiners []Joiner, ...) ([]string, []*Tuple, error)
- func (t *Transaction) RelationAttribute(schName, relName, attrName string) (int, Attribute, error)
- func (t *Transaction) Rollback()
- func (t *Transaction) Truncate(schema, relation string) (int64, error)
- func (t *Transaction) Update(schema, relation string, values map[string]any, selectors []Selector, ...) ([]string, []*Tuple, error)
- type TruePredicate
- func (p *TruePredicate) Attribute() []string
- func (p *TruePredicate) Eval([]string, *Tuple) (bool, error)
- func (p *TruePredicate) Left() (Predicate, bool)
- func (p *TruePredicate) Relation() string
- func (p *TruePredicate) Right() (Predicate, bool)
- func (p TruePredicate) String() string
- func (p *TruePredicate) Type() PredicateType
- type Tuple
- type Updater
- type ValueChange
- type ValueFunctor
Constants ¶
const (
DefaultSchema = "public"
)
Variables ¶
var (
NotImplemented = errors.New("not implemented")
)
Functions ¶
func PrintQueryPlan ¶
PrintQueryPlan
func ToInstance ¶
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) 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 (Attribute) HasAutoIncrement ¶
func (Attribute) WithAutoIncrement ¶
func (Attribute) WithDefault ¶
func (Attribute) WithDefaultConst ¶
func (Attribute) WithDefaultNow ¶
func (Attribute) WithUnique ¶
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) 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
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
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
type Deleter ¶
type Deleter struct {
// contains filtered or unexported fields
}
func (*Deleter) EstimateCardinal ¶
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) Priority ¶
func (d *DistinctSorter) Priority() int
func (*DistinctSorter) SetNode ¶
func (d *DistinctSorter) SetNode(n Node)
func (DistinctSorter) String ¶
func (s DistinctSorter) String() string
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) 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) 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) 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) 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) 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 ¶
func NewHashIndex ¶
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) 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 IndexSrc ¶
type IndexSrc struct {
// contains filtered or unexported fields
}
func NewHashIndexSource ¶
func (*IndexSrc) EstimateCardinal ¶
type Joiner ¶
Joiner joins two relation together.
Should be able to estimate cardinality of join for cost optimization.
Possible implementations:
- NaturalJoiner
- LeftOuterJoiner
- RightOuterJoiner
- FullOuterJoiner
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) 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) 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) 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 (*ListNode) EstimateCardinal ¶
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) 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) 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) 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
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) 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) 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) 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 ¶
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 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) String ¶
func (s RelationScanner) String() string
type Scanner ¶
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 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) 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 Sorter ¶
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.
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) 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) 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 ¶
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) 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()
type TruePredicate ¶
type TruePredicate struct { }
func NewTruePredicate ¶
func NewTruePredicate() *TruePredicate
func (*TruePredicate) Attribute ¶
func (p *TruePredicate) Attribute() []string
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
type Updater ¶
type Updater struct {
// contains filtered or unexported fields
}
func NewUpdaterNode ¶
func (*Updater) EstimateCardinal ¶
type ValueChange ¶
type ValueChange struct {
// contains filtered or unexported fields
}
type ValueFunctor ¶
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()