mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-09-10 13:11:32 +00:00
basic support for EXPLAIN and EVAL
This commit is contained in:
@@ -84,6 +84,8 @@ func TestExplain(t *testing.T) {
|
||||
"insert": "Cannot explain cmd: insert",
|
||||
"mapreduce": "Cannot explain cmd: mapReduce",
|
||||
"update": "<nil>",
|
||||
"explain": "Cannot explain cmd: explain",
|
||||
"eval": "Cannot explain cmd: eval",
|
||||
}
|
||||
|
||||
expectError := map[string]string{}
|
||||
|
@@ -81,20 +81,31 @@ func (f *Fingerprint) Fingerprint(doc proto.SystemProfile) (string, error) {
|
||||
switch doc.Op {
|
||||
case "remove", "update":
|
||||
op = doc.Op
|
||||
ns := strings.Split(doc.Ns, ".")
|
||||
ns := strings.SplitN(doc.Ns, ".", 2)
|
||||
if len(ns) == 2 {
|
||||
collection = ns[1]
|
||||
}
|
||||
case "insert":
|
||||
op = doc.Op
|
||||
ns := strings.Split(doc.Ns, ".")
|
||||
ns := strings.SplitN(doc.Ns, ".", 2)
|
||||
if len(ns) == 2 {
|
||||
collection = ns[1]
|
||||
}
|
||||
retKeys = []string{}
|
||||
case "query":
|
||||
// EXPLAIN MongoDB 2.6:
|
||||
// "query" : {
|
||||
// "query" : {
|
||||
//
|
||||
// },
|
||||
// "$explain" : true
|
||||
// },
|
||||
if _, ok := doc.Query.Map()["$explain"]; ok {
|
||||
op = "explain"
|
||||
break
|
||||
}
|
||||
op = "find"
|
||||
ns := strings.Split(doc.Ns, ".")
|
||||
ns := strings.SplitN(doc.Ns, ".", 2)
|
||||
if len(ns) == 2 {
|
||||
collection = ns[1]
|
||||
}
|
||||
@@ -140,6 +151,12 @@ func (f *Fingerprint) Fingerprint(doc proto.SystemProfile) (string, error) {
|
||||
}
|
||||
case "geoNear":
|
||||
retKeys = []string{}
|
||||
case "explain":
|
||||
retKeys = []string{}
|
||||
case "$eval":
|
||||
op = "eval"
|
||||
collection = ""
|
||||
retKeys = []string{}
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -113,6 +113,16 @@ func TestFingerprints(t *testing.T) {
|
||||
"distinct_3.2.16": "DISTINCT coll a,b",
|
||||
"distinct_3.4.7": "DISTINCT coll a,b",
|
||||
"distinct_3.5.11": "DISTINCT coll a,b",
|
||||
"explain_2.6.12": "EXPLAIN",
|
||||
"explain_3.0.15": "EXPLAIN",
|
||||
"explain_3.2.16": "EXPLAIN",
|
||||
"explain_3.4.7": "EXPLAIN",
|
||||
"explain_3.5.11": "EXPLAIN",
|
||||
"eval_2.6.12": "EVAL",
|
||||
"eval_3.0.15": "EVAL",
|
||||
"eval_3.2.16": "EVAL",
|
||||
"eval_3.4.7": "EVAL",
|
||||
"eval_3.5.11": "EVAL",
|
||||
"find_empty_2.6.12": "FIND coll",
|
||||
"find_empty_3.0.15": "FIND coll",
|
||||
"find_empty_3.2.16": "FIND coll",
|
||||
|
@@ -120,6 +120,22 @@ func (self ExampleQuery) ExplainCmd() bson.D {
|
||||
if cmd.Len() == 0 {
|
||||
cmd = self.Query
|
||||
}
|
||||
|
||||
// MongoDB 2.6:
|
||||
//
|
||||
// "query" : {
|
||||
// "query" : {
|
||||
//
|
||||
// },
|
||||
// "$explain" : true
|
||||
// },
|
||||
if _, ok := cmd.Map()["$explain"]; ok {
|
||||
cmd = BsonD{
|
||||
{"explain", ""},
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if cmd.Len() == 0 || cmd[0].Name != "find" {
|
||||
var filter interface{}
|
||||
if cmd.Len() > 0 && cmd[0].Name == "query" {
|
||||
|
1
src/go/tests/doc/script/profile/eval.js
Normal file
1
src/go/tests/doc/script/profile/eval.js
Normal file
@@ -0,0 +1 @@
|
||||
db.eval("db")
|
3
src/go/tests/doc/script/profile/explain.js
Normal file
3
src/go/tests/doc/script/profile/explain.js
Normal file
@@ -0,0 +1,3 @@
|
||||
var coll = db.coll
|
||||
|
||||
coll.find().explain()
|
Reference in New Issue
Block a user