Skip to content

Commit

Permalink
sql: fix distsql planning issue with optimizer (streaming aggregation)
Browse files Browse the repository at this point in the history
The distsql planner looks at physical properties of various plan nodes
to figure out what orderings it needs to preserve when merging data
from multiple nodes. These are passed as required orderings in the
exec.Factory, but not for all operators - only those for which it
would actually matter.

There is a code path related to setting up streaming aggregations
which was unaccounted for which looks at the ordering of the input
node.

To fix this, we now pass required orderings to filters and
projections. I looked at all the operators and the rest either:
 - never produce an ordering as far as the optimizer is concerned
   (VirtualScan, HashJoin, ScalarGroupBy, SetOp, ProjectSet); or
 - they pass through the input ordering unchanged (Distinct); or
 - they cannot be distributed (Limit, Ordinality).

Release note (bug fix): Fixed an issue which causes invalid results or
an "incorrectly ordered stream" error with streaming aggregations (in
some cases).
  • Loading branch information
RaduBerinde committed Oct 25, 2018
1 parent b720b8b commit f04fc30
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 131 deletions.
8 changes: 5 additions & 3 deletions pkg/sql/opt/bench/stub_factory.go
Expand Up @@ -47,18 +47,20 @@ func (f *stubFactory) ConstructVirtualScan(table opt.Table) (exec.Node, error) {
return struct{}{}, nil
}

func (f *stubFactory) ConstructFilter(n exec.Node, filter tree.TypedExpr) (exec.Node, error) {
func (f *stubFactory) ConstructFilter(
n exec.Node, filter tree.TypedExpr, reqOrdering exec.OutputOrdering,
) (exec.Node, error) {
return struct{}{}, nil
}

func (f *stubFactory) ConstructSimpleProject(
n exec.Node, cols []exec.ColumnOrdinal, colNames []string,
n exec.Node, cols []exec.ColumnOrdinal, colNames []string, reqOrdering exec.OutputOrdering,
) (exec.Node, error) {
return struct{}{}, nil
}

func (f *stubFactory) ConstructRender(
n exec.Node, exprs tree.TypedExprs, colNames []string,
n exec.Node, exprs tree.TypedExprs, colNames []string, reqOrdering exec.OutputOrdering,
) (exec.Node, error) {
return struct{}{}, nil
}
Expand Down

0 comments on commit f04fc30

Please sign in to comment.