On Wed, Nov 8, 2017 at 3:18 AM, Tom Lane <t...@sss.pgh.pa.us> wrote: > Robert Haas <robertmh...@gmail.com> writes: >> I think it would be a good idea, as Thomas says, to order the qual >> clauses at an earlier stage and then remember our decision. However, >> we have to think about whether that's going to increase planning time >> in a noticeable way. I wonder why we currently postpone this until >> such a late phase of planning. > > Because (1) up to now there's been no need to consider the qual ordering > till later, and (2) re-doing that sort for each path seemed unduly > expensive. If we're to try to estimate whether later quals will be > reached, then sure the ordering becomes important. I'm still concerned > about (2) though. If there were a way to pre-sort the quals once for > all paths, the problem goes away, but I don't think that works --- > indexscans may segregate some quals, and in join cases different paths > will actually have different sets of quals they need to check depending > on the join order. >
Looking at order_qual_clauses(), we can say that a set of quals q1 .... qn are ordered the same irrespective of the set of clauses they are subset of. E.g. if {q1 .. qn} is subset of Q (ordered as Qo) and also Q' (ordered as Q'o) the order in which they appear in Qo and Q'o is same. So, even if different paths segregate the clauses in different set, within each set the order is same. FWIW, we can order all clauses in largest set once and use that order every time. Albeit we will have to remember the order somewhere OR make the separator routine retain the order in the larger set, which I guess is true about all separator functions. -- Best Wishes, Ashutosh Bapat EnterpriseDB Corporation The Postgres Database Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers