diff --git a/lib/cartodb/api/filter_stats_api.js b/lib/cartodb/api/filter_stats_api.js index 5196d2fa..d872ad8c 100644 --- a/lib/cartodb/api/filter_stats_api.js +++ b/lib/cartodb/api/filter_stats_api.js @@ -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); });