From 3396214a63fef04b5f1bdd5abea573e614c036cc Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Wed, 21 Oct 2015 12:52:40 +0200 Subject: [PATCH] added db._explain() convenience function --- .../js/modules/org/arangodb/arango-database.js | 16 ++++++++++++++++ .../frontend/js/modules/org/arangodb/arangosh.js | 1 + .../modules/org/arangodb/arango-database.js | 16 ++++++++++++++++ js/client/modules/org/arangodb/arangosh.js | 1 + .../modules/org/arangodb/arango-database.js | 16 ++++++++++++++++ 5 files changed, 50 insertions(+) diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/modules/org/arangodb/arango-database.js b/js/apps/system/_admin/aardvark/APP/frontend/js/modules/org/arangodb/arango-database.js index df1f2fb0a2..ff937cd022 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/modules/org/arangodb/arango-database.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/modules/org/arangodb/arango-database.js @@ -827,6 +827,22 @@ ArangoDatabase.prototype._query = function (query, bindVars, cursorOptions, opti return new ArangoStatement(this, data).execute(); }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief explains a query +//////////////////////////////////////////////////////////////////////////////// + +ArangoDatabase.prototype._explain = function (query, bindVars, options) { + if (typeof query === 'object' && typeof query.toAQL === 'function') { + query = { query: query.toAQL() }; + } + + if (arguments.length > 1) { + query = { query: query, bindVars: bindVars, options: options }; + } + + require("org/arangodb/aql/explainer").explain(query); +}; + // ----------------------------------------------------------------------------- // --SECTION-- database functions // ----------------------------------------------------------------------------- diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/modules/org/arangodb/arangosh.js b/js/apps/system/_admin/aardvark/APP/frontend/js/modules/org/arangodb/arangosh.js index b3c71ec044..80cdc07a33 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/modules/org/arangodb/arangosh.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/modules/org/arangodb/arangosh.js @@ -129,6 +129,7 @@ exports.HELP = exports.createHelpHeadline("Help") + 'Examples: ' + "\n" + ' > db._collections() list all collections ' + "\n" + ' > db._query().toArray() execute an AQL query ' + "\n" + + ' > db._explain() explain an AQL query ' + "\n" + ' > help show help pages ' + "\n" + ' > exit ' + "\n" + 'Note: collection names and statuses may be cached in arangosh. ' + "\n" + diff --git a/js/client/modules/org/arangodb/arango-database.js b/js/client/modules/org/arangodb/arango-database.js index b75740df54..f28a5d4ebc 100644 --- a/js/client/modules/org/arangodb/arango-database.js +++ b/js/client/modules/org/arangodb/arango-database.js @@ -826,6 +826,22 @@ ArangoDatabase.prototype._query = function (query, bindVars, cursorOptions, opti return new ArangoStatement(this, data).execute(); }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief explains a query +//////////////////////////////////////////////////////////////////////////////// + +ArangoDatabase.prototype._explain = function (query, bindVars, options) { + if (typeof query === 'object' && typeof query.toAQL === 'function') { + query = { query: query.toAQL() }; + } + + if (arguments.length > 1) { + query = { query: query, bindVars: bindVars, options: options }; + } + + require("org/arangodb/aql/explainer").explain(query); +}; + // ----------------------------------------------------------------------------- // --SECTION-- database functions // ----------------------------------------------------------------------------- diff --git a/js/client/modules/org/arangodb/arangosh.js b/js/client/modules/org/arangodb/arangosh.js index 6481955b4d..bb21519609 100644 --- a/js/client/modules/org/arangodb/arangosh.js +++ b/js/client/modules/org/arangodb/arangosh.js @@ -128,6 +128,7 @@ exports.HELP = exports.createHelpHeadline("Help") + 'Examples: ' + "\n" + ' > db._collections() list all collections ' + "\n" + ' > db._query().toArray() execute an AQL query ' + "\n" + + ' > db._explain() explain an AQL query ' + "\n" + ' > help show help pages ' + "\n" + ' > exit ' + "\n" + 'Note: collection names and statuses may be cached in arangosh. ' + "\n" + diff --git a/js/server/modules/org/arangodb/arango-database.js b/js/server/modules/org/arangodb/arango-database.js index 0851a1555d..0081e4633d 100644 --- a/js/server/modules/org/arangodb/arango-database.js +++ b/js/server/modules/org/arangodb/arango-database.js @@ -106,6 +106,22 @@ ArangoDatabase.prototype._query = function (query, bindVars, cursorOptions, opti return new ArangoStatement(this, payload).execute(); }; +//////////////////////////////////////////////////////////////////////////////// +/// @brief explains a query +//////////////////////////////////////////////////////////////////////////////// + +ArangoDatabase.prototype._explain = function (query, bindVars, options) { + if (typeof query === 'object' && typeof query.toAQL === 'function') { + query = { query: query.toAQL() }; + } + + if (arguments.length > 1) { + query = { query: query, bindVars: bindVars, options: options }; + } + + require("org/arangodb/aql/explainer").explain(query); +}; + // ----------------------------------------------------------------------------- // --SECTION-- transactions // -----------------------------------------------------------------------------