Generate stats used to identify category columns in overviews if needed

This only generates the stats if no stats are available for a table.
This doesn't warrant that the stats are up to date or accurate.
This commit is contained in:
Javier Goizueta 2016-04-27 15:06:09 +02:00
parent 2c43943df6
commit a067cc7da1

View File

@ -557,10 +557,20 @@ AS $$
DECLARE
schema_name TEXT;
table_name TEXT;
available BOOLEAN;
categorical BOOLEAN;
BEGIN
SELECT * FROM _cdb_split_table_name(reloid) INTO schema_name, table_name;
SELECT n_distinct IS NOT NULL AND n_distinct > 0 AND n_distinct <= 20
SELECT n_distinct IS NOT NULL
FROM pg_stats
WHERE pg_stats.schemaname = schema_name
AND pg_stats.tablename = table_name
AND pg_stats.attname = col_name
INTO available;
IF available IS NULL OR NOT available THEN
EXECUTE Format('ANALYZE %s;', reloid);
END IF;
SELECT n_distinct > 0 AND n_distinct <= 20
FROM pg_stats
WHERE pg_stats.schemaname = schema_name
AND pg_stats.tablename = table_name
@ -568,7 +578,7 @@ BEGIN
INTO categorical;
RETURN categorical;
END;
$$ LANGUAGE PLPGSQL STABLE;
$$ LANGUAGE PLPGSQL VOLATILE;
CREATE OR REPLACE FUNCTION _cdb_mode_of_array(anyarray)
RETURNS anyelement AS