Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix some typo and continue refactor variable name topn #3505

Merged
merged 2 commits into from
Jun 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ func (b *executorBuilder) buildSort(v *plan.Sort) Executor {
schema: v.Schema(),
}
if v.ExecLimit != nil {
return &TopnExec{
return &TopNExec{
SortExec: sortExec,
limit: v.ExecLimit,
}
Expand All @@ -699,7 +699,7 @@ func (b *executorBuilder) buildTopN(v *plan.TopN) Executor {
ByItems: v.ByItems,
schema: v.Schema(),
}
return &TopnExec{
return &TopNExec{
SortExec: sortExec,
limit: &plan.Limit{Count: v.Count, Offset: v.Offset},
}
Expand Down
4 changes: 2 additions & 2 deletions executor/distsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,15 +641,15 @@ func (e *XSelectIndexExec) doIndexRequest() (distsql.SelectResult, error) {
if e.desc {
selIdxReq.OrderBy = []*tipb.ByItem{{Desc: e.desc}}
}
// If the index is single read, we can push topn down.
// If the index is single read, we can push topN down.
if e.singleReadMode {
selIdxReq.Limit = e.limitCount
// If sortItemsPB is empty, the Desc may be true and we shouldn't overwrite it.
if len(e.sortItemsPB) > 0 {
selIdxReq.OrderBy = e.sortItemsPB
}
} else if e.where == nil && len(e.sortItemsPB) == 0 {
// If the index is double read but table scan has no filter or topn, we can push limit down to index.
// If the index is double read but table scan has no filter or topN, we can push limit down to index.
selIdxReq.Limit = e.limitCount
}
selIdxReq.Where = e.indexConditionPBExpr
Expand Down
2 changes: 1 addition & 1 deletion executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ var (
_ Executor = &StreamAggExec{}
_ Executor = &TableDualExec{}
_ Executor = &TableScanExec{}
_ Executor = &TopnExec{}
_ Executor = &TopNExec{}
_ Executor = &UnionExec{}
)

Expand Down
14 changes: 7 additions & 7 deletions executor/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,17 @@ func (e *SortExec) Next() (*Row, error) {
return row, nil
}

// TopnExec implements a Top-N algorithm and it is built from a SELECT statement with ORDER BY and LIMIT.
// TopNExec implements a Top-N algorithm and it is built from a SELECT statement with ORDER BY and LIMIT.
// Instead of sorting all the rows fetched from the table, it keeps the Top-N elements only in a heap to reduce memory usage.
type TopnExec struct {
type TopNExec struct {
SortExec
limit *plan.Limit
totalCount int
heapSize int
}

// Less implements heap.Interface Less interface.
func (e *TopnExec) Less(i, j int) bool {
func (e *TopNExec) Less(i, j int) bool {
sc := e.ctx.GetSessionVars().StmtCtx
for index, by := range e.ByItems {
v1 := e.Rows[i].key[index]
Expand All @@ -165,24 +165,24 @@ func (e *TopnExec) Less(i, j int) bool {
}

// Len implements heap.Interface Len interface.
func (e *TopnExec) Len() int {
func (e *TopNExec) Len() int {
return e.heapSize
}

// Push implements heap.Interface Push interface.
func (e *TopnExec) Push(x interface{}) {
func (e *TopNExec) Push(x interface{}) {
e.Rows = append(e.Rows, x.(*orderByRow))
e.heapSize++
}

// Pop implements heap.Interface Pop interface.
func (e *TopnExec) Pop() interface{} {
func (e *TopNExec) Pop() interface{} {
e.heapSize--
return nil
}

// Next implements the Executor Next interface.
func (e *TopnExec) Next() (*Row, error) {
func (e *TopNExec) Next() (*Row, error) {
if !e.fetched {
e.Idx = int(e.limit.Offset)
e.totalCount = int(e.limit.Offset + e.limit.Count)
Expand Down
4 changes: 2 additions & 2 deletions kv/buffer_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ func (s *BufferStore) Seek(k Key) (Iterator, error) {

// SeekReverse implements the Retriever interface.
func (s *BufferStore) SeekReverse(k Key) (Iterator, error) {
buferIt, err := s.MemBuffer.SeekReverse(k)
bufferIt, err := s.MemBuffer.SeekReverse(k)
if err != nil {
return nil, errors.Trace(err)
}
retrieverIt, err := s.r.SeekReverse(k)
if err != nil {
return nil, errors.Trace(err)
}
return newUnionIter(buferIt, retrieverIt, true), nil
return newUnionIter(bufferIt, retrieverIt, true), nil
}

// WalkBuffer iterates all buffered kv pairs.
Expand Down
8 changes: 4 additions & 4 deletions kv/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
const (
codeClosed terror.ErrCode = 1
codeNotExist = 2
codeCondithinNotMatch = 3
codeLockConfilict = 4
codeConditionNotMatch = 3
codeLockConflict = 4
codeLazyConditionPairsNotMatch = 5
codeRetryable = 6
codeCantSetNilValue = 7
Expand All @@ -44,9 +44,9 @@ var (
// ErrNotExist is used when try to get an entry with an unexist key from KV store.
ErrNotExist = terror.ClassKV.New(codeNotExist, "Error: key not exist")
// ErrConditionNotMatch is used when condition is not met.
ErrConditionNotMatch = terror.ClassKV.New(codeCondithinNotMatch, "Error: Condition not match")
ErrConditionNotMatch = terror.ClassKV.New(codeConditionNotMatch, "Error: Condition not match")
// ErrLockConflict is used when try to lock an already locked key.
ErrLockConflict = terror.ClassKV.New(codeLockConfilict, "Error: Lock conflict")
ErrLockConflict = terror.ClassKV.New(codeLockConflict, "Error: Lock conflict")
// ErrLazyConditionPairsNotMatch is used when value in store differs from expect pairs.
ErrLazyConditionPairsNotMatch = terror.ClassKV.New(codeLazyConditionPairsNotMatch, "Error: Lazy condition pairs not match")
// ErrRetryable is used when KV store occurs RPC error or some other
Expand Down
2 changes: 1 addition & 1 deletion kv/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (k Key) Next() Key {
// rowkey1_column2
// rowKey2
//
// If we seek 'rowkey1' Next, we will get 'rowkey1_colum1'.
// If we seek 'rowkey1' Next, we will get 'rowkey1_column1'.
// If we seek 'rowkey1' PrefixNext, we will get 'rowkey2'.
func (k Key) PrefixNext() Key {
buf := make([]byte, len([]byte(k)))
Expand Down
2 changes: 1 addition & 1 deletion plan/physical_plans.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func (p *PhysicalMemTable) Copy() PhysicalPlan {
}

// physicalDistSQLPlan means the plan that can be executed distributively.
// We can push down other plan like selection, limit, aggregation, topn into this plan.
// We can push down other plan like selection, limit, aggregation, topN into this plan.
type physicalDistSQLPlan interface {
addAggregation(ctx context.Context, agg *PhysicalAggregation) *expression.Schema
addTopN(ctx context.Context, prop *requiredProperty) bool
Expand Down
8 changes: 4 additions & 4 deletions store/localstore/local_region.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ type selectContext struct {
// TODO: Only one of these three flags can be true at the same time. We should set this as an enum var.
aggregate bool
descScan bool
topn bool
topN bool

// Use for DecodeRow.
colTps map[int64]*types.FieldType
Expand Down Expand Up @@ -221,7 +221,7 @@ func (rs *localRegion) Handle(req *regionRequest) (*regionResponse, error) {
if sel.Limit == nil {
return nil, errors.New("we don't support pushing down Sort without Limit")
}
ctx.topn = true
ctx.topN = true
ctx.topnHeap = &topnHeap{
totalCount: int(*sel.Limit),
topnSorter: topnSorter{
Expand Down Expand Up @@ -269,7 +269,7 @@ func (rs *localRegion) Handle(req *regionRequest) (*regionResponse, error) {
}
err = rs.getRowsFromIndexReq(ctx)
}
if ctx.topn {
if ctx.topN {
rs.setTopNDataForCtx(ctx)
}
selResp := new(tipb.SelectResponse)
Expand Down Expand Up @@ -593,7 +593,7 @@ func (rs *localRegion) valuesToRow(ctx *selectContext, handle int64, values map[
if !match {
return false, nil
}
if ctx.topn {
if ctx.topN {
return false, errors.Trace(rs.evalTopN(ctx, handle, values, columns))
}
if ctx.aggregate {
Expand Down