Merge pull request #878 from nieyy/master

performance_schema: initial empty tables
This commit is contained in:
goroutine
2016-01-25 21:18:21 +08:00
5 changed files with 1106 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import (
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/mysql"
"github.com/pingcap/tidb/optimizer/plan"
"github.com/pingcap/tidb/perfschema"
"github.com/pingcap/tidb/terror"
)
@ -81,6 +82,8 @@ func (c *supportChecker) Enter(in ast.Node) (ast.Node, bool) {
c.unsupported = true
} else if strings.EqualFold(tn.Schema.O, infoschema.Name) {
c.unsupported = true
} else if strings.EqualFold(tn.Schema.O, perfschema.Name) {
c.unsupported = true
}
}
}

19
perfschema/perfschema.go Normal file
View File

@ -0,0 +1,19 @@
// Copyright 2016 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
// Performance Schema Name.
const (
Name = "PERFORMANCE_SCHEMA"
)

1015
plan/plans/perf.go Normal file

File diff suppressed because it is too large Load Diff

65
plan/plans/perf_test.go Normal file
View File

@ -0,0 +1,65 @@
// Copyright 2016 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 plans_test
import (
"database/sql"
. "github.com/pingcap/check"
"github.com/pingcap/tidb"
)
type testPerfSchemaSuit struct {
vars map[string]interface{}
}
var _ = Suite(&testPerfSchemaSuit{
vars: make(map[string]interface{}),
})
func (p *testPerfSchemaSuit) TestPerfSchema(c *C) {
testDB, err := sql.Open(tidb.DriverName, tidb.EngineGoLevelDBMemory+"/test/test")
c.Assert(err, IsNil)
cnt := mustQuery(c, testDB, "select * from performance_schema.setup_actors")
c.Assert(cnt, Equals, 1)
cnt = mustQuery(c, testDB, "select * from performance_schema.setup_objects")
c.Assert(cnt, Equals, 12)
// Note: so far, there has no instrumentation point yet
cnt = mustQuery(c, testDB, "select * from performance_schema.setup_instruments")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.setup_consumers")
c.Assert(cnt, Equals, 12)
cnt = mustQuery(c, testDB, "select * from performance_schema.setup_timers")
c.Assert(cnt, Equals, 3)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_statements_current")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_statements_history")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_statements_history_long")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.prepared_statements_instances")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_transactions_current")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_transactions_history")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_transactions_history_long")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_stages_current")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_stages_history")
c.Assert(cnt, Equals, 0)
cnt = mustQuery(c, testDB, "select * from performance_schema.events_stages_history_long")
c.Assert(cnt, Equals, 0)
}

View File

@ -26,6 +26,7 @@ import (
"github.com/pingcap/tidb/field"
"github.com/pingcap/tidb/infoschema"
"github.com/pingcap/tidb/model"
"github.com/pingcap/tidb/perfschema"
"github.com/pingcap/tidb/plan"
"github.com/pingcap/tidb/plan/plans"
"github.com/pingcap/tidb/sessionctx"
@ -48,6 +49,9 @@ func (r *TableRset) Plan(ctx context.Context) (plan.Plan, error) {
if strings.EqualFold(r.Schema, infoschema.Name) {
return plans.NewInfoSchemaPlan(r.Name)
}
if strings.EqualFold(r.Schema, perfschema.Name) {
return plans.NewPerfSchemaPlan(r.Name)
}
is := sessionctx.GetDomain(ctx).InfoSchema()
t, err := is.TableByName(model.NewCIStr(r.Schema), model.NewCIStr(r.Name))
if err != nil {