>
> Hi Richard,
> Thanks for the patch. Extracting the shared restrictions upfront and
> bypassing innerrel_is_unique() is a much cleaner design, and it nicely
> fixes the index-order dependency.
> I read through the patch and had two minor thoughts:
> 1. Maybe I'm overthinking this, but now that SJE no longer goes through
> innerrel_is_unique(), we no longer call rel_supports_distinctness()
> anywhere in the SJE path.
> Previously, if restrictlist was NIL we skipped the pair immediately;
> otherwise innerrel_is_unique_ext() checked rel_supports_distinctness()
> before calling relation_has_unique_index_for(), and match_unique_clauses()
> (which does copyObject() + ChangeVarNodes() + equal()) was only called
> after a unique index match succeeded.
> With this patch, we also proceed when restrictlist is NIL, and
> get_shared_restrictions() is called before relation_has_unique_index_for().
> So if a query self-joins a table that has no usable unique index (e.g., no
> indexes at all, or only non-unique / partial / deferred unique indexes),
> remove_self_joins_one_group() will still run
> generate_join_implied_equalities(), split_selfjoin_quals(), and
> get_shared_restrictions() for every candidate pair in the group, only for
> relation_has_unique_index_for() to find no usable unique index.
> Other callers such as join_is_removable() and reduce_unique_semijoins()
> check rel_supports_distinctness() before building the clause lists.
> Since all relations in remove_self_joins_one_group() share the same
> reloid (and have !rte->inh), would it be worth checking
> rel_supports_distinctness() once in remove_self_joins_one_group() so that
> we can skip the whole group early if the table has no suitable unique
> index?
> 2. In remove_self_joins_one_group(), otherjoinquals was previously only
> needed for the "list_length(otherjoinquals) == 0" argument to
> innerrel_is_unique_ext(). With that call gone, otherjoinquals is only
> used in:
> Assert(list_length(restrictlist) ==
> (list_length(selfjoinquals) + list_length(otherjoinquals)));
> Perhaps we can drop otherjoinquals and simplify split_selfjoin_quals() to
> just return the list of self-join quals (similar to
> get_shared_restrictions())?
>
> Thanks