From e1aa0bc7ae302ea16d6766988b3d929ed85c1ab3 Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Wed, 18 May 2016 13:09:55 +0200 Subject: [PATCH] Use JSON format for EXPLAIN --- lib/cartodb/api/filter_stats_api.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) 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); });