From 4767bc8ff2edc1258cf4d8a83155d4cedd724231 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Thu, 16 Feb 2012 17:33:28 -0500 Subject: Improve statistics estimation to make some use of DISTINCT in sub-queries. Formerly, we just punted when trying to estimate stats for variables coming out of sub-queries using DISTINCT, on the grounds that whatever stats we might have for underlying table columns would be inapplicable. But if the sub-query has only one DISTINCT column, we can consider its output variable as being unique, which is useful information all by itself. The scope of this improvement is pretty narrow, but it costs nearly nothing, so we might as well do it. Per discussion with Andres Freund. This patch differs from the draft I submitted yesterday in updating various comments about vardata.isunique (to reflect its extended meaning) and in tweaking the interaction with security_barrier views. There does not seem to be a reason why we can't use this sort of knowledge even when the sub-query is such a view. --- src/include/utils/selfuncs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/include/utils/selfuncs.h') diff --git a/src/include/utils/selfuncs.h b/src/include/utils/selfuncs.h index 78eda1b503f..bffc2d80ef0 100644 --- a/src/include/utils/selfuncs.h +++ b/src/include/utils/selfuncs.h @@ -74,7 +74,7 @@ typedef struct VariableStatData Oid vartype; /* exposed type of expression */ Oid atttype; /* type to pass to get_attstatsslot */ int32 atttypmod; /* typmod to pass to get_attstatsslot */ - bool isunique; /* true if matched to a unique index */ + bool isunique; /* matches unique index or DISTINCT clause */ } VariableStatData; #define ReleaseVariableStats(vardata) \ -- cgit v1.2.3