Skip to content

Commit

Permalink
edits
Browse files Browse the repository at this point in the history
  • Loading branch information
max-hoffman committed Dec 8, 2023
1 parent 1b50eb0 commit d3f4abd
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 15 deletions.
1 change: 0 additions & 1 deletion sql/analyzer/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var OnceAfterDefault = []Rule{
{stripTableNameInDefaultsId, stripTableNamesFromColumnDefaults},
{pushFiltersId, pushFilters},
{optimizeJoinsId, optimizeJoins},
//{generateIndexScansId, costedIndexScans},
{finalizeSubqueriesId, finalizeSubqueries},
{applyIndexesFromOuterScopeId, applyIndexesFromOuterScope},
{replaceAggId, replaceAgg},
Expand Down
5 changes: 0 additions & 5 deletions sql/memo/coster.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,6 @@ func exprReferencesTable(e sql.Expression, tabId sql.TableId) bool {
func (c *coster) costLookupJoin(_ *sql.Context, n *LookupJoin, _ sql.StatsProvider) (float64, error) {
l := n.Left.RelProps.card
r := n.Right.RelProps.card
//if stat := n.Lookup.First.(*IndexScan).Group().RelProps.stat; stat != nil && stat.RowCount() > 0 {
// return l*float64(stat.RowCount())*(cpuCostFactor+randIOCostFactor) - r*seqIOCostFactor, nil
//}
lookup := n.Lookup.First.(*IndexScan)
var sel float64
if isInjectiveLookup(lookup.Index, n.JoinBase, lookup.Table.Expressions(), lookup.Table.NullMask()) {
Expand Down Expand Up @@ -440,9 +437,7 @@ func (c *coster) costFilter(_ *sql.Context, f *Filter, _ sql.StatsProvider) (flo
}

func (c *coster) costIndexScan(_ *sql.Context, f *IndexScan, _ sql.StatsProvider) (float64, error) {
// 1 unit of compute for each input row
return 0, nil
//return float64(f.Group().RelProps.stat.RowCount()) * cpuCostFactor, nil
}

func NewDefaultCarder() Carder {
Expand Down
13 changes: 6 additions & 7 deletions sql/memo/expr_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,22 +106,21 @@ func (e *ExprGroup) finalize(node sql.Node) (sql.Node, error) {
func (e *ExprGroup) fixEnforcers() {
switch n := e.Best.(type) {
case *MergeJoin:
// no ITA children that aren't the same index as sorting index
n.Left.fixItaConflict(n.InnerScan)
n.Right.fixItaConflict(n.OuterScan)
// todo: no ITA children that aren't the same index as sorting index
n.Left.fixItaConflict()
n.Right.fixItaConflict()
case *LookupJoin:
// no ITA children
n.Right.fixItaConflict(nil)
n.Right.fixItaConflict()
}
}

func (e *ExprGroup) fixItaConflict(i *IndexScan) {
// this should do a DFS to find the path to the underlying table
// Update best to a DFS path to a tablescan
func (e *ExprGroup) fixItaConflict() {
e.findTableScanPath()
}

func (e *ExprGroup) findTableScanPath() bool {
// there is only one path to a tablescan, that needs to be best
n := e.First
for n != nil {
src, ok := n.(SourceRel)
Expand Down
2 changes: 0 additions & 2 deletions sql/memo/rel_props.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,15 +356,13 @@ func (p *relProps) populateOutputTables() {
p.tableNodes = []plan.TableIdNode{n.TableIdNode()}
case *AntiJoin:
p.outputTables = n.Left.RelProps.OutputTables()
//p.tableNodes = n.Left.RelProps.TableIdNodes()
leftNodeCnt := len(n.JoinPrivate().Left.RelProps.tableNodes)
rightNodeCnt := len(n.JoinPrivate().Right.RelProps.tableNodes)
p.tableNodes = make([]plan.TableIdNode, leftNodeCnt+rightNodeCnt)
copy(p.tableNodes, n.JoinPrivate().Left.RelProps.tableNodes)
copy(p.tableNodes[leftNodeCnt:], n.JoinPrivate().Right.RelProps.tableNodes)
case *SemiJoin:
p.outputTables = n.Left.RelProps.OutputTables()
//p.tableNodes = n.Left.RelProps.TableIdNodes()
leftNodeCnt := len(n.JoinPrivate().Left.RelProps.tableNodes)
rightNodeCnt := len(n.JoinPrivate().Right.RelProps.tableNodes)
p.tableNodes = make([]plan.TableIdNode, leftNodeCnt+rightNodeCnt)
Expand Down

0 comments on commit d3f4abd

Please sign in to comment.