Skip to content

Commit

Permalink
Merge #29026
Browse files Browse the repository at this point in the history
29026: opt: Increase performance of small queries r=andy-kimball a=andy-kimball

This PR contains two commits that increase the performance of
small, simple queries:

- Improve statistics building perf
- Streamline join name dup detection

Together, these changes result in these bench test improvements:
```
name                      old time/op  new time/op  delta
Phases/kv-read/Explore    28.0µs ± 2%  26.1µs ± 3%  -6.94%  (p=0.008 n=5+5)
Phases/planning1/Explore  10.5µs ± 3%  10.3µs ± 2%    ~     (p=0.310 n=5+5)
Phases/planning2/Explore  31.2µs ± 2%  30.7µs ± 3%    ~     (p=0.222 n=5+5)
Phases/planning3/Explore  36.2µs ± 2%  34.3µs ± 3%  -5.28%  (p=0.008 n=5+5)
Phases/planning4/Explore  44.2µs ± 1%  41.5µs ± 2%  -6.00%  (p=0.008 n=5+5)
Phases/planning5/Explore  35.9µs ± 1%  34.1µs ± 2%  -5.10%  (p=0.008 n=5+5)
Phases/planning6/Explore  63.8µs ± 3%  59.3µs ± 3%  -7.12%  (p=0.008 n=5+5)
```

Co-authored-by: Andrew Kimball <andyk@cockroachlabs.com>
  • Loading branch information
craig[bot] and andy-kimball committed Aug 27, 2018
2 parents 9c45896 + 6f6490a commit e7d570e
Show file tree
Hide file tree
Showing 12 changed files with 518 additions and 237 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/opt/memo/expr_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (ev ExprView) FormatString(flags ExprFmtFlags) string {
// This is used for testing.
func (ev ExprView) RequestColStat(evalCtx *tree.EvalContext, cols opt.ColSet) {
var sb statisticsBuilder
sb.init(evalCtx, ev.Metadata(), &keyBuffer{})
sb.init(evalCtx, ev.Metadata())
sb.colStat(cols, ev)
}

Expand Down
29 changes: 14 additions & 15 deletions pkg/sql/opt/memo/logical_props_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ var fdAnnID = opt.NewTableAnnID()
type logicalPropsBuilder struct {
evalCtx *tree.EvalContext
sb statisticsBuilder
kb keyBuffer
relationalAlloc []props.Relational
scalarAlloc []props.Scalar
}
Expand Down Expand Up @@ -181,7 +180,7 @@ func (b *logicalPropsBuilder) buildScanProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, md, &b.kb)
b.sb.init(b.evalCtx, md)
b.sb.buildScan(ev, relational)

return logical
Expand Down Expand Up @@ -217,7 +216,7 @@ func (b *logicalPropsBuilder) buildVirtualScanProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildVirtualScan(ev, relational)

return logical
Expand Down Expand Up @@ -279,7 +278,7 @@ func (b *logicalPropsBuilder) buildSelectProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildSelect(ev, relational)

return logical
Expand Down Expand Up @@ -369,7 +368,7 @@ func (b *logicalPropsBuilder) buildProjectProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildProject(ev, relational)

return logical
Expand Down Expand Up @@ -530,7 +529,7 @@ func (b *logicalPropsBuilder) buildJoinProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildJoin(ev, relational)

return logical
Expand Down Expand Up @@ -575,7 +574,7 @@ func (b *logicalPropsBuilder) buildIndexJoinProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, md, &b.kb)
b.sb.init(b.evalCtx, md)
b.sb.buildIndexJoin(ev, relational)

return logical
Expand Down Expand Up @@ -638,7 +637,7 @@ func (b *logicalPropsBuilder) buildGroupByProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildGroupBy(ev, relational)

return logical
Expand Down Expand Up @@ -696,7 +695,7 @@ func (b *logicalPropsBuilder) buildSetProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildSetOp(ev, relational)

return logical
Expand Down Expand Up @@ -737,7 +736,7 @@ func (b *logicalPropsBuilder) buildValuesProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildValues(ev, relational)

return logical
Expand Down Expand Up @@ -868,7 +867,7 @@ func (b *logicalPropsBuilder) buildLimitProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildLimit(ev, relational)

return logical
Expand Down Expand Up @@ -923,7 +922,7 @@ func (b *logicalPropsBuilder) buildOffsetProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildOffset(ev, relational)

return logical
Expand Down Expand Up @@ -962,7 +961,7 @@ func (b *logicalPropsBuilder) buildMax1RowProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildMax1Row(ev, relational)

return logical
Expand Down Expand Up @@ -1011,7 +1010,7 @@ func (b *logicalPropsBuilder) buildRowNumberProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildRowNumber(ev, relational)

return logical
Expand Down Expand Up @@ -1048,7 +1047,7 @@ func (b *logicalPropsBuilder) buildZipProps(ev ExprView) props.Logical {

// Statistics
// ----------
b.sb.init(b.evalCtx, ev.Metadata(), &b.kb)
b.sb.init(b.evalCtx, ev.Metadata())
b.sb.buildZip(ev, relational)

return logical
Expand Down
10 changes: 0 additions & 10 deletions pkg/sql/opt/memo/private_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -608,16 +608,6 @@ func (kb *keyBuffer) writeColList(colList opt.ColList) {
}
}

// writeGroupList writes a series of varints, one for each column in the list,
// in list order.
func (kb *keyBuffer) writeGroupList(groupList []GroupID) {
var buf [10]byte
for _, col := range groupList {
cnt := binary.PutUvarint(buf[:], uint64(col))
kb.Write(buf[:cnt])
}
}

// writePhysProps writes the presentation columns, followed by the ordering
// spec.
func (kb *keyBuffer) writePhysProps(physical *props.Physical) {
Expand Down
Loading

0 comments on commit e7d570e

Please sign in to comment.