Re: Unclamped row estimates whith OR-ed subplans

From: "Benjamin Coutu" <ben(dot)coutu(at)zeyos(dot)com>
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Unclamped row estimates whith OR-ed subplans
Date: 2020-06-19 20:33:15
Message-ID: 20200619203316.68FB05FB27@mx.zeyos.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

> While you're waiting, you might think about recasting the query to
> avoid the OR. Perhaps you could do a UNION of two scans of the
> transactions table?

Thanks for the hint, I am well aware of the workaround for OR via UNION. I am not trying to improve this query per se as it is the small root of a very complex generated query and it's unfeasible to rewrite it to a UNION in this case.

The point of my message to the list was to highlight the misestimation, which I couldn't wrap my head around. Maybe this discussion can give some food for thought to someone who might tackle this in the future. It would surely be great to have selectivity estimate smarts for the generic case of OR-ed SubPlans someday.

>
> > Btw, I don't quite understand why the nested loop on contract only is expected to yield 31662 rows, when the null_frac of field transactions.contract is 1. Shouldn't that indicate zero rows or some kind of default minimum estimate for that query?
>
> That I don't understand. I get a minimal rowcount estimate for an
> all-nulls outer table, as long as I'm using just one IN rather than

Yeah, that might be worth digging into. Is there any other info apart from those stats that I could provide?

Browse pgsql-performance by date

  From Date Subject
Next Message Kenneth Marshall 2020-06-19 20:49:50 Re: PostgreSQL 12.3 slow index scan chosen
Previous Message Tom Lane 2020-06-19 20:11:10 Re: PostgreSQL 12.3 slow index scan chosen