Skip to content

Commit

Permalink
infoschema: move perfschema to infoschema directory, tiny refactor (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored and zz-jason committed Jan 10, 2019
1 parent 0bc0f7d commit 3b40b14
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 164 deletions.
2 changes: 1 addition & 1 deletion domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ import (
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/infoschema/perfschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/metrics"
"github.com/pingcap/tidb/owner"
"github.com/pingcap/tidb/perfschema"
"github.com/pingcap/tidb/privilege/privileges"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
Expand Down
3 changes: 1 addition & 2 deletions infoschema/infoschema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/perfschema"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/types"
"github.com/pingcap/tidb/util/testleak"
Expand Down Expand Up @@ -120,7 +119,7 @@ func (*testSuite) TestT(c *C) {

schemaNames := is.AllSchemaNames()
c.Assert(schemaNames, HasLen, 3)
c.Assert(testutil.CompareUnorderedStringSlice(schemaNames, []string{infoschema.Name, perfschema.Name, "Test"}), IsTrue)
c.Assert(testutil.CompareUnorderedStringSlice(schemaNames, []string{infoschema.Name, "PERFORMANCE_SCHEMA", "Test"}), IsTrue)

schemas := is.AllSchemas()
c.Assert(schemas, HasLen, 3)
Expand Down
File renamed without changes.
File renamed without changes.
66 changes: 66 additions & 0 deletions infoschema/perfschema/tables.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2017 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

package perfschema

import (
"github.com/pingcap/parser/model"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/meta/autoid"
"github.com/pingcap/tidb/table"
)

// perfSchemaTable stands for the fake table all its data is in the memory.
type perfSchemaTable struct {
infoschema.VirtualTable
meta *model.TableInfo
cols []*table.Column
}

func tableFromMeta(alloc autoid.Allocator, meta *model.TableInfo) (table.Table, error) {
return createPerfSchemaTable(meta), nil
}

// createPerfSchemaTable creates all perfSchemaTables
func createPerfSchemaTable(meta *model.TableInfo) *perfSchemaTable {
columns := make([]*table.Column, 0, len(meta.Columns))
for _, colInfo := range meta.Columns {
col := table.ToColumn(colInfo)
columns = append(columns, col)
}
t := &perfSchemaTable{
meta: meta,
cols: columns,
}
return t
}

// Cols implements table.Table Type interface.
func (vt *perfSchemaTable) Cols() []*table.Column {
return vt.cols
}

// WritableCols implements table.Table Type interface.
func (vt *perfSchemaTable) WritableCols() []*table.Column {
return vt.cols
}

// GetID implements table.Table GetID interface.
func (vt *perfSchemaTable) GetPhysicalID() int64 {
return vt.meta.ID
}

// Meta implements table.Table Type interface.
func (vt *perfSchemaTable) Meta() *model.TableInfo {
return vt.meta
}
File renamed without changes.
117 changes: 117 additions & 0 deletions infoschema/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -1603,3 +1603,120 @@ func (it *infoschemaTable) Seek(ctx sessionctx.Context, h int64) (int64, bool, e
func (it *infoschemaTable) Type() table.Type {
return table.VirtualTable
}

// VirtualTable is a dummy table.Table implementation.
type VirtualTable struct{}

// IterRecords implements table.Table Type interface.
func (vt *VirtualTable) IterRecords(ctx sessionctx.Context, startKey kv.Key, cols []*table.Column,
fn table.RecordIterFunc) error {
if len(startKey) != 0 {
return table.ErrUnsupportedOp
}
return nil
}

// RowWithCols implements table.Table Type interface.
func (vt *VirtualTable) RowWithCols(ctx sessionctx.Context, h int64, cols []*table.Column) ([]types.Datum, error) {
return nil, table.ErrUnsupportedOp
}

// Row implements table.Table Type interface.
func (vt *VirtualTable) Row(ctx sessionctx.Context, h int64) ([]types.Datum, error) {
return nil, table.ErrUnsupportedOp
}

// Cols implements table.Table Type interface.
func (vt *VirtualTable) Cols() []*table.Column {
return nil
}

// WritableCols implements table.Table Type interface.
func (vt *VirtualTable) WritableCols() []*table.Column {
return nil
}

// Indices implements table.Table Type interface.
func (vt *VirtualTable) Indices() []table.Index {
return nil
}

// WritableIndices implements table.Table Type interface.
func (vt *VirtualTable) WritableIndices() []table.Index {
return nil
}

// DeletableIndices implements table.Table Type interface.
func (vt *VirtualTable) DeletableIndices() []table.Index {
return nil
}

// RecordPrefix implements table.Table Type interface.
func (vt *VirtualTable) RecordPrefix() kv.Key {
return nil
}

// IndexPrefix implements table.Table Type interface.
func (vt *VirtualTable) IndexPrefix() kv.Key {
return nil
}

// FirstKey implements table.Table Type interface.
func (vt *VirtualTable) FirstKey() kv.Key {
return nil
}

// RecordKey implements table.Table Type interface.
func (vt *VirtualTable) RecordKey(h int64) kv.Key {
return nil
}

// AddRecord implements table.Table Type interface.
func (vt *VirtualTable) AddRecord(ctx sessionctx.Context, r []types.Datum, opts ...*table.AddRecordOpt) (recordID int64, err error) {
return 0, table.ErrUnsupportedOp
}

// RemoveRecord implements table.Table Type interface.
func (vt *VirtualTable) RemoveRecord(ctx sessionctx.Context, h int64, r []types.Datum) error {
return table.ErrUnsupportedOp
}

// UpdateRecord implements table.Table Type interface.
func (vt *VirtualTable) UpdateRecord(ctx sessionctx.Context, h int64, oldData, newData []types.Datum, touched []bool) error {
return table.ErrUnsupportedOp
}

// AllocAutoID implements table.Table Type interface.
func (vt *VirtualTable) AllocAutoID(ctx sessionctx.Context) (int64, error) {
return 0, table.ErrUnsupportedOp
}

// Allocator implements table.Table Type interface.
func (vt *VirtualTable) Allocator(ctx sessionctx.Context) autoid.Allocator {
return nil
}

// RebaseAutoID implements table.Table Type interface.
func (vt *VirtualTable) RebaseAutoID(ctx sessionctx.Context, newBase int64, isSetStep bool) error {
return table.ErrUnsupportedOp
}

// Meta implements table.Table Type interface.
func (vt *VirtualTable) Meta() *model.TableInfo {
return nil
}

// GetPhysicalID implements table.Table GetPhysicalID interface.
func (vt *VirtualTable) GetPhysicalID() int64 {
return 0
}

// Seek implements table.Table Type interface.
func (vt *VirtualTable) Seek(ctx sessionctx.Context, h int64) (int64, bool, error) {
return 0, false, table.ErrUnsupportedOp
}

// Type implements table.Table Type interface.
func (vt *VirtualTable) Type() table.Type {
return table.VirtualTable
}
161 changes: 0 additions & 161 deletions perfschema/tables.go

This file was deleted.

0 comments on commit 3b40b14

Please sign in to comment.