From 564ab75d2d4cc3797aa8c24262d2598e41eb22bd Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Mon, 21 Dec 2015 18:34:26 +0100 Subject: [PATCH] Use _cdb_estimated_extent instead of ST_Extent With a 3.8M points table, this was a ~30% gain in my local env. --- scripts-available/CDB_Overviews.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts-available/CDB_Overviews.sql b/scripts-available/CDB_Overviews.sql index a72d48d..5d94b09 100644 --- a/scripts-available/CDB_Overviews.sql +++ b/scripts-available/CDB_Overviews.sql @@ -71,7 +71,7 @@ AS $$ -- considered tiles. EXECUTE Format(' WITH RECURSIVE t(x, y, z, e) AS ( - WITH ext AS (SELECT ST_Extent(the_geom_webmercator) g FROM %1$s), + WITH ext AS (SELECT _cdb_estimated_extent(%6$s) as g), base AS ( SELECT (-floor(log(2, (greatest(ST_XMax(ext.g)-ST_XMin(ext.g), ST_YMax(ext.g)-ST_YMin(ext.g))/(%4$s*%5$s))::numeric)))::integer z FROM ext @@ -101,7 +101,7 @@ AS $$ WHERE t.e > %2$s AND t.z < (base.z + %3$s) ) SELECT MAX(e/ST_Area(CDB_XYZ_Extent(x,y,z))) FROM t where e > 0; - ', reloid::text, min_features, nz, n, c) + ', reloid::text, min_features, nz, n, c, reloid::oid) INTO fd; RETURN fd; END