Use JSON format for EXPLAIN
This commit is contained in:
parent
3987e83b7a
commit
e1aa0bc7ae
@ -9,19 +9,15 @@ function FilterStatsApi(pgQueryRunner) {
|
|||||||
module.exports = FilterStatsApi;
|
module.exports = FilterStatsApi;
|
||||||
|
|
||||||
function getEstimatedRows(pgQueryRunner, username, query, callback) {
|
function getEstimatedRows(pgQueryRunner, username, query, callback) {
|
||||||
pgQueryRunner.run(username, "EXPLAIN "+query, function(err, result_rows) {
|
pgQueryRunner.run(username, "EXPLAIN (FORMAT JSON)"+query, function(err, result_rows) {
|
||||||
if (err){
|
if (err){
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var rows;
|
var rows;
|
||||||
var query_plan = result_rows[0]['QUERY PLAN'];
|
if ( result_rows[0] && result_rows[0]['QUERY PLAN'] &&
|
||||||
var match;
|
result_rows[0]['QUERY PLAN'][0] && result_rows[0]['QUERY PLAN'][0].Plan ) {
|
||||||
if ( query_plan ) {
|
rows = result_rows[0]['QUERY PLAN'][0].Plan['Plan Rows'];
|
||||||
match = query_plan.match(/rows=(\d+)/);
|
|
||||||
}
|
|
||||||
if ( match ) {
|
|
||||||
rows = +match[1];
|
|
||||||
}
|
}
|
||||||
return callback(null, rows);
|
return callback(null, rows);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user