From 234373df1143d53296ccc9ad92997f22c3ef28ca Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Mon, 10 Apr 2017 08:08:59 +0200 Subject: [PATCH] Replace unnecessary count --- scripts-available/CDB_EstimateRowCount.sql | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts-available/CDB_EstimateRowCount.sql b/scripts-available/CDB_EstimateRowCount.sql index 353b963..6be76b0 100644 --- a/scripts-available/CDB_EstimateRowCount.sql +++ b/scripts-available/CDB_EstimateRowCount.sql @@ -3,10 +3,12 @@ CREATE OR REPLACE FUNCTION _CDB_GenerateStats(reloid REGCLASS) RETURNS VOID AS $$ DECLARE - num_cols INTEGER; + has_stats BOOLEAN; BEGIN - SELECT COUNT(*) FROM pg_catalog.pg_statistic WHERE starelid = reloid INTO num_cols; - IF num_cols = 0 THEN + SELECT EXISTS ( + SELECT * FROM pg_catalog.pg_statistic WHERE starelid = reloid + ) INTO has_stats; + IF NOT has_stats THEN EXECUTE Format('ANALYZE %s;', reloid); END IF; END