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