Skip to content

Commit 9248fe2

Browse files
author
James Cor
committed
remove sort over merge joins
1 parent 5098278 commit 9248fe2

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

sql/analyzer/replace_sort.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func replaceIdxSortHelper(ctx *sql.Context, scope *plan.Scope, node sql.Node, so
5454
return n, transform.SameTree, nil
5555
}
5656

57+
// TODO: verify that we don't need to look at other SortFields?
5758
// if the lookup does not need any reversing, do nothing
5859
if sortNode.SortFields[0].Order != sql.Descending {
5960
return n, transform.NewTree, nil
@@ -126,6 +127,7 @@ func replaceIdxSortHelper(ctx *sql.Context, scope *plan.Scope, node sql.Node, so
126127
if err != nil {
127128
return nil, transform.SameTree, err
128129
}
130+
// TODO: what about the other sort fields?
129131
if sortNode.SortFields[0].Order == sql.Descending {
130132
lookup = sql.NewIndexLookup(
131133
lookup.Index,
@@ -159,6 +161,22 @@ func replaceIdxSortHelper(ctx *sql.Context, scope *plan.Scope, node sql.Node, so
159161
switch c := child.(type) {
160162
case *plan.Project, *plan.TableAlias, *plan.ResolvedTable, *plan.Filter, *plan.Limit, *plan.Offset, *plan.Sort, *plan.IndexedTableAccess, *plan.Distinct:
161163
newChildren[i], same, err = replaceIdxSortHelper(ctx, scope, child, sortNode)
164+
case *plan.JoinNode:
165+
if !c.JoinType().IsMerge() {
166+
continue
167+
}
168+
// TODO: skipping desc sorting for now
169+
hasDesc := false
170+
for _, sf := range sortNode.SortFields {
171+
if sf.Order == sql.Descending {
172+
hasDesc = true
173+
break
174+
}
175+
}
176+
if hasDesc {
177+
continue
178+
}
179+
newChildren[i], same, err = replaceIdxSortHelper(ctx, scope, child, sortNode)
162180
default:
163181
newChildren[i] = c
164182
}

sql/rowexec/rel_iters.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ func (i *offsetIter) Next(ctx *sql.Context) (sql.Row, error) {
110110
}
111111
i.skip--
112112
}
113+
114+
// TODO: if i.childIter implements Offsetable Table?
113115
}
114116

115117
row, err := i.childIter.Next(ctx)

0 commit comments

Comments
 (0)