Skip to content

Commit dfd2ffe

Browse files
DvirDukhangkorland
andauthored
added cached execution statistics (#54)
* added cached execution statistics * Update label.js * Update redisGraphAPITest.js * Update redisGraphAPITest.js Co-authored-by: Guy Korland <gkorland@gmail.com>
1 parent 4ec7412 commit dfd2ffe

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

src/label.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var Label = Object.freeze({
1111
RELATIONSHIPS_CREATED: "Relationships created",
1212
INDICES_CREATED: "Indices created",
1313
INDICES_DELETED: "Indices deleted",
14+
CACHED_EXECUTION: "Cached execution",
1415
QUERY_INTERNAL_EXECUTION_TIME: "Query internal execution time"
1516
});
1617

src/statistics.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ class Statistics {
108108
*/
109109
indicesDeleted() {
110110
return this.getIntValue(Label.INDICES_DELETED);
111-
}
111+
}
112+
113+
/**
114+
* @returns {boolean} The execution plan was cached on RedisGraph.
115+
*/
116+
cachedExecution() {
117+
return this.getIntValue(Label.CACHED_EXECUTION) == 1;
118+
}
112119

113120
/**
114121
* @returns {float} The query execution time in ms.

test/redisGraphAPITest.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,5 +508,33 @@ describe("RedisGraphAPI Test", () => {
508508
record = resultSet.next();
509509
assert.equal(record.size(), 1);
510510
assert.equal(record.get(0), null);
511-
});
511+
});
512+
513+
it("testCachedExecution", async () => {
514+
await api.query("CREATE (:N {val:1}), (:N {val:2})");
515+
516+
// First time should not be loaded from execution cache
517+
let resultSet = await api.query(
518+
"MATCH (n:N {val:$val}) RETURN n.val ", {'val':1}
519+
);
520+
assert.equal(resultSet.size(), 1)
521+
assert.equal(false, resultSet.getStatistics().cachedExecution())
522+
523+
let record = resultSet.next();
524+
assert.equal(record.size(), 1);
525+
assert.equal(record.get(0), 1);
526+
527+
// Run in loop many times to make sure the query will be loaded
528+
// from cache at least once
529+
for (var i = 0; i < 64; i++) {
530+
resultSet = await api.query(
531+
"MATCH (n:N {val:$val}) RETURN n.val ", {'val':1}
532+
);
533+
}
534+
assert.equal(resultSet.size(), 1)
535+
record = resultSet.next();
536+
assert.equal(record.size(), 1);
537+
assert.equal(record.get(0), 1);
538+
assert.equal(true, resultSet.getStatistics().cachedExecution())
539+
});
512540
});

0 commit comments

Comments
 (0)