diff --git a/NEWS.md b/NEWS.md index e03a601f..d4a88f33 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # Changelog +## 5.3.1 +Released yyyy-mm-dd + - Improve the speed of the aggregation dataview #865 + ## 5.3.0 Released 2018-02-12 - Upgrades redis-mpool to 0.5.0 diff --git a/lib/cartodb/models/dataview/aggregation.js b/lib/cartodb/models/dataview/aggregation.js index fed5e14e..568d3cc2 100644 --- a/lib/cartodb/models/dataview/aggregation.js +++ b/lib/cartodb/models/dataview/aggregation.js @@ -2,19 +2,17 @@ const BaseDataview = require('./base'); const debug = require('debug')('windshaft:dataview:aggregation'); const filteredQueryTpl = ctx => ` - filtered_source AS ( - SELECT * - FROM (${ctx.query}) _cdb_filtered_source - ${ctx.aggregationColumn && ctx.isFloatColumn ? ` - WHERE - ${ctx.aggregationColumn} != 'infinity'::float - AND - ${ctx.aggregationColumn} != '-infinity'::float - AND - ${ctx.aggregationColumn} != 'NaN'::float` : - '' - } - ) + SELECT * + FROM (${ctx.query}) _cdb_filtered_source + ${ctx.aggregationColumn && ctx.isFloatColumn ? ` + WHERE + ${ctx.aggregationColumn} != 'infinity'::float + AND + ${ctx.aggregationColumn} != '-infinity'::float + AND + ${ctx.aggregationColumn} != 'NaN'::float` : + '' + } `; const summaryQueryTpl = ctx => ` @@ -43,7 +41,7 @@ const rankedCategoriesQueryTpl = ctx => ` ${ctx.column} AS category, ${ctx.aggregationFn} AS value, row_number() OVER (ORDER BY ${ctx.aggregationFn} desc) as rank - FROM filtered_source + FROM (${filteredQueryTpl(ctx)}) filtered_source ${ctx.aggregationColumn !== null ? `WHERE ${ctx.aggregationColumn} IS NOT NULL` : ''} GROUP BY ${ctx.column} ORDER BY 2 DESC @@ -134,7 +132,6 @@ const aggregationFnQueryTpl = ctx => `${ctx.aggregation}(${ctx.aggregationColumn const aggregationDataviewQueryTpl = ctx => ` WITH - ${filteredQueryTpl(ctx)}, ${summaryQueryTpl(ctx)}, ${rankedCategoriesQueryTpl(ctx)}, ${categoriesSummaryMinMaxQueryTpl(ctx)}, diff --git a/package.json b/package.json index 8e3d6917..b9540a97 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "windshaft-cartodb", - "version": "5.3.0", + "version": "5.3.1", "description": "A map tile server for CartoDB", "keywords": [ "cartodb"