Subject: Re: Statistics Import and Export

From: Corey Huinker <[email-masked]>
Date: Wed, 2 Apr 2025 22:34:58 -0400

>
> > Also, why do we need the clause "WHERE s.tablename = ANY($2)"? Isn't
> > that already implied by "JOIN unnest($1, $2) ... s.tablename =
> > u.tablename"?
>
> Good question.  Corey, do you recall why this was needed?
>

In my patch, that SQL statement came with the comment:

+ /*
+ * The results must be in the order of relations supplied in the
+ * parameters to ensure that they are in sync with a walk of the TOC.
+ *
+ * The redundant (and incomplete) filter clause on s.tablename = ANY(...)
+ * is a way to lead the query into using the index
+ * pg_class_relname_nsp_index which in turn allows the planner to avoid an
+ * expensive full scan of pg_stats.
+ *
+ * We may need to adjust this query for versions that are not so easily
+ * led.
+ */

---

From: Nathan Bossart <[email-masked]>
Date: Wed, 2 Apr 2025 21:38:18 -0500

> + * We may need to adjust this query for versions that are not so easily

Thanks.  I included that in the latest patch set.

-- 
nathan