From 32306244ff5f8f7d839a349ae62a421d3b5f318f Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Mon, 7 Aug 2017 13:40:16 +0800 Subject: [PATCH] domain,executor: ignore restricted sql for statement count metrics To make the statement count metrics more precise, we should ignore some background job such as update statistics and load privilege. --- domain/domain.go | 2 ++ executor/compiler.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/domain/domain.go b/domain/domain.go index 07d12449afeaf..8a608ff2a3b8e 100644 --- a/domain/domain.go +++ b/domain/domain.go @@ -454,6 +454,7 @@ func (do *Domain) SysSessionPool() *pools.ResourcePool { // LoadPrivilegeLoop create a goroutine loads privilege tables in a loop, it // should be called only once in BootstrapSession. func (do *Domain) LoadPrivilegeLoop(ctx context.Context) error { + ctx.GetSessionVars().InRestrictedSQL = true do.privHandle = privileges.NewHandle() err := do.privHandle.Update(ctx) if err != nil { @@ -517,6 +518,7 @@ func (do *Domain) CreateStatsHandle(ctx context.Context) { // UpdateTableStatsLoop creates a goroutine loads stats info and updates stats info in a loop. It // should be called only once in BootstrapSession. func (do *Domain) UpdateTableStatsLoop(ctx context.Context) error { + ctx.GetSessionVars().InRestrictedSQL = true do.statsHandle = statistics.NewHandle(ctx, do.statsLease) do.ddl.RegisterEventCh(do.statsHandle.DDLEventCh()) err := do.statsHandle.Update(do.InfoSchema()) diff --git a/executor/compiler.go b/executor/compiler.go index d04762839dede..b85b17da31820 100644 --- a/executor/compiler.go +++ b/executor/compiler.go @@ -42,7 +42,12 @@ func (c *Compiler) Compile(ctx context.Context, node ast.StmtNode) (ast.Statemen if err != nil { return nil, errors.Trace(err) } - isExpensive := stmtCount(node, p) + + var isExpensive bool + if !ctx.GetSessionVars().InRestrictedSQL { + // Don't take restricted SQL into account for metrics. + isExpensive = stmtCount(node, p) + } sa := &statement{ is: is, plan: p,