From 73c56e4df5311c928f00575342ee49725d15029e Mon Sep 17 00:00:00 2001 From: Tobie Morgan Hitchcock Date: Thu, 23 Feb 2017 10:11:52 +0000 Subject: [PATCH] Log sql queries centrally, not separately --- db/create.go | 6 ------ db/db.go | 6 ++++++ db/define.go | 41 ----------------------------------------- db/delete.go | 6 ------ db/info.go | 6 ------ db/let.go | 6 ------ db/relate.go | 6 ------ db/remove.go | 41 ----------------------------------------- db/return.go | 6 ------ db/select.go | 6 ------ db/update.go | 6 ------ 11 files changed, 6 insertions(+), 130 deletions(-) diff --git a/db/create.go b/db/create.go index cdd3697c..5632cc0f 100644 --- a/db/create.go +++ b/db/create.go @@ -16,7 +16,6 @@ package db import ( "fmt" - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/item" "github.com/abcum/surreal/util/keys" @@ -25,11 +24,6 @@ import ( func (e *executor) executeCreateStatement(ast *sql.CreateStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - for k, w := range ast.What { if what, ok := w.(*sql.Param); ok { ast.What[k] = e.ctx.Get(what.ID).Data() diff --git a/db/db.go b/db/db.go index a1c3846b..e52bd8d1 100644 --- a/db/db.go +++ b/db/db.go @@ -310,6 +310,12 @@ func (e *executor) execute(quit <-chan bool, send chan<- *Response) { err, now = nil, time.Now() } + // When in debugging mode, log every sql + // query, along with the query execution + // speed, so we can analyse slow queries. + + log.WithPrefix("sql").Debugln(stm) + // Check to see if the current statement is // a TRANSACTION statement, and if it is // then deal with it and move on to the next. diff --git a/db/define.go b/db/define.go index f3ff0e3d..b77b072c 100644 --- a/db/define.go +++ b/db/define.go @@ -15,7 +15,6 @@ package db import ( - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/item" "github.com/abcum/surreal/util/keys" @@ -24,11 +23,6 @@ import ( func (e *executor) executeDefineNamespaceStatement(ast *sql.DefineNamespaceStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Set the namespace nkey := &keys.NS{KV: ast.KV, NS: ast.Name} _, err = e.txn.Put(0, nkey.Encode(), ast.Encode()) @@ -39,11 +33,6 @@ func (e *executor) executeDefineNamespaceStatement(ast *sql.DefineNamespaceState func (e *executor) executeDefineDatabaseStatement(ast *sql.DefineDatabaseStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Set the namespace nkey := &keys.NS{KV: ast.KV, NS: ast.NS} nval := &sql.DefineNamespaceStatement{Name: ast.NS} @@ -59,11 +48,6 @@ func (e *executor) executeDefineDatabaseStatement(ast *sql.DefineDatabaseStateme func (e *executor) executeDefineLoginStatement(ast *sql.DefineLoginStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - if ast.Kind == sql.NAMESPACE { // Set the namespace @@ -101,11 +85,6 @@ func (e *executor) executeDefineLoginStatement(ast *sql.DefineLoginStatement) (o func (e *executor) executeDefineTokenStatement(ast *sql.DefineTokenStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - if ast.Kind == sql.NAMESPACE { // Set the namespace @@ -143,11 +122,6 @@ func (e *executor) executeDefineTokenStatement(ast *sql.DefineTokenStatement) (o func (e *executor) executeDefineScopeStatement(ast *sql.DefineScopeStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Set the namespace nkey := &keys.NS{KV: ast.KV, NS: ast.NS} nval := &sql.DefineNamespaceStatement{Name: ast.NS} @@ -168,11 +142,6 @@ func (e *executor) executeDefineScopeStatement(ast *sql.DefineScopeStatement) (o func (e *executor) executeDefineTableStatement(ast *sql.DefineTableStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Set the namespace nkey := &keys.NS{KV: ast.KV, NS: ast.NS} nval := &sql.DefineNamespaceStatement{Name: ast.NS} @@ -199,11 +168,6 @@ func (e *executor) executeDefineTableStatement(ast *sql.DefineTableStatement) (o func (e *executor) executeDefineFieldStatement(ast *sql.DefineFieldStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Set the namespace nkey := &keys.NS{KV: ast.KV, NS: ast.NS} nval := &sql.DefineNamespaceStatement{Name: ast.NS} @@ -235,11 +199,6 @@ func (e *executor) executeDefineFieldStatement(ast *sql.DefineFieldStatement) (o func (e *executor) executeDefineIndexStatement(ast *sql.DefineIndexStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Set the namespace nkey := &keys.NS{KV: ast.KV, NS: ast.NS} nval := &sql.DefineNamespaceStatement{Name: ast.NS} diff --git a/db/delete.go b/db/delete.go index 37f77179..59d2bfab 100644 --- a/db/delete.go +++ b/db/delete.go @@ -16,7 +16,6 @@ package db import ( "fmt" - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/item" "github.com/abcum/surreal/util/keys" @@ -24,11 +23,6 @@ import ( func (e *executor) executeDeleteStatement(ast *sql.DeleteStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - for k, w := range ast.What { if what, ok := w.(*sql.Param); ok { ast.What[k] = e.ctx.Get(what.ID).Data() diff --git a/db/info.go b/db/info.go index 94a5b661..b96c85bf 100644 --- a/db/info.go +++ b/db/info.go @@ -15,18 +15,12 @@ package db import ( - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/data" ) func (e *executor) executeInfoStatement(ast *sql.InfoStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - switch ast.Kind { case sql.NAMESPACE: return e.executeInfoNSStatement(ast) diff --git a/db/let.go b/db/let.go index b9ecde3f..6e757c81 100644 --- a/db/let.go +++ b/db/let.go @@ -15,17 +15,11 @@ package db import ( - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" ) func (e *executor) executeLetStatement(ast *sql.LetStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - switch what := ast.What.(type) { default: e.Set(ast.Name, what) diff --git a/db/relate.go b/db/relate.go index 17531a00..a1cf0930 100644 --- a/db/relate.go +++ b/db/relate.go @@ -15,17 +15,11 @@ package db import ( - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" ) func (e *executor) executeRelateStatement(ast *sql.RelateStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - return nil, nil } diff --git a/db/remove.go b/db/remove.go index fc31a32a..ce8f026f 100644 --- a/db/remove.go +++ b/db/remove.go @@ -15,18 +15,12 @@ package db import ( - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/keys" ) func (e *executor) executeRemoveNamespaceStatement(ast *sql.RemoveNamespaceStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Remove the namespace nkey := &keys.NS{KV: ast.KV, NS: ast.Name} _, err = e.txn.DelP(0, nkey.Encode(), 0) @@ -37,11 +31,6 @@ func (e *executor) executeRemoveNamespaceStatement(ast *sql.RemoveNamespaceState func (e *executor) executeRemoveDatabaseStatement(ast *sql.RemoveDatabaseStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Remove the database dkey := &keys.DB{KV: ast.KV, NS: ast.NS, DB: ast.Name} _, err = e.txn.DelP(0, dkey.Encode(), 0) @@ -52,11 +41,6 @@ func (e *executor) executeRemoveDatabaseStatement(ast *sql.RemoveDatabaseStateme func (e *executor) executeRemoveLoginStatement(ast *sql.RemoveLoginStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - if ast.Kind == sql.NAMESPACE { // Remove the login @@ -79,11 +63,6 @@ func (e *executor) executeRemoveLoginStatement(ast *sql.RemoveLoginStatement) (o func (e *executor) executeRemoveTokenStatement(ast *sql.RemoveTokenStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - if ast.Kind == sql.NAMESPACE { // Remove the token @@ -106,11 +85,6 @@ func (e *executor) executeRemoveTokenStatement(ast *sql.RemoveTokenStatement) (o func (e *executor) executeRemoveScopeStatement(ast *sql.RemoveScopeStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - // Remove the scope skey := &keys.SC{KV: ast.KV, NS: ast.NS, DB: ast.DB, SC: ast.Name} _, err = e.txn.DelP(0, skey.Encode(), 0) @@ -121,11 +95,6 @@ func (e *executor) executeRemoveScopeStatement(ast *sql.RemoveScopeStatement) (o func (e *executor) executeRemoveTableStatement(ast *sql.RemoveTableStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - for _, TB := range ast.What { // Remove the table @@ -140,11 +109,6 @@ func (e *executor) executeRemoveTableStatement(ast *sql.RemoveTableStatement) (o func (e *executor) executeRemoveFieldStatement(ast *sql.RemoveFieldStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - for _, TB := range ast.What { // Remove the field @@ -159,11 +123,6 @@ func (e *executor) executeRemoveFieldStatement(ast *sql.RemoveFieldStatement) (o func (e *executor) executeRemoveIndexStatement(ast *sql.RemoveIndexStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - for _, TB := range ast.What { // Remove the index diff --git a/db/return.go b/db/return.go index 0d643116..4e5ef384 100644 --- a/db/return.go +++ b/db/return.go @@ -15,17 +15,11 @@ package db import ( - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" ) func (e *executor) executeReturnStatement(ast *sql.ReturnStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - switch what := ast.What.(type) { default: out = append(out, what) diff --git a/db/select.go b/db/select.go index eb51356c..13f5e41a 100644 --- a/db/select.go +++ b/db/select.go @@ -15,7 +15,6 @@ package db import ( - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/item" "github.com/abcum/surreal/util/keys" @@ -23,11 +22,6 @@ import ( func (e *executor) executeSelectStatement(ast *sql.SelectStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - for k, w := range ast.What { if what, ok := w.(*sql.Param); ok { ast.What[k] = e.ctx.Get(what.ID).Data() diff --git a/db/update.go b/db/update.go index 49e5434d..99dde54a 100644 --- a/db/update.go +++ b/db/update.go @@ -16,7 +16,6 @@ package db import ( "fmt" - "github.com/abcum/surreal/log" "github.com/abcum/surreal/sql" "github.com/abcum/surreal/util/item" "github.com/abcum/surreal/util/keys" @@ -24,11 +23,6 @@ import ( func (e *executor) executeUpdateStatement(ast *sql.UpdateStatement) (out []interface{}, err error) { - log.WithPrefix("sql").WithFields(map[string]interface{}{ - "ns": ast.NS, - "db": ast.DB, - }).Debugln(ast) - for k, w := range ast.What { if what, ok := w.(*sql.Param); ok { ast.What[k] = e.ctx.Get(what.ID).Data()