Re: Unclamped row estimates whith OR-ed subplans

2020-06-19 Thread Benjamin Coutu
> 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 roo

Re: Unclamped row estimates whith OR-ed subplans

2020-06-19 Thread Michael Lewis
> > 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? > Minor note- use UNION ALL to avoid the dedupe work if you already know those will be distinct sets, or having duplicates is fine.

Re: Unclamped row estimates whith OR-ed subplans

2020-06-19 Thread Tom Lane
"Benjamin Coutu" writes: > I don't want to waste your time but maybe there is room for improvement as > both "account" and "contract" are highly distinct and the individual subplan > estimates are quite accurate: Yeah, as I said, the estimates you're getting for the OR'd subplans are pretty stu

Re: Unclamped row estimates whith OR-ed subplans

2020-06-19 Thread Benjamin Coutu
> No. The subplan estimates are for the number of rows produced by one > execution of the subplan, ie the numbers of "accounts" or "contracts" > rows that match those inner WHERE conditions. This has very little > a-priori relationship to the number of "transactions" rows that will > satisfy the

Re: Unclamped row estimates whith OR-ed subplans

2020-06-19 Thread David G. Johnston
On Friday, June 19, 2020, Laurenz Albe wrote: > > > I am absolutely aware that those are hashed sub plans below a seqscan > and that Postgres therefore has to scan all tuples of the table. But the > problem is that upper nodes (which are excluded from > > this example for simplicity) think they w

Re: Unclamped row estimates whith OR-ed subplans

2020-06-19 Thread Tom Lane
"Benjamin Coutu" writes: > please consider the following SQL query: > SELECT * FROM "transactions" WHERE > "account" IN (SELECT "ID" FROM "accounts" WHERE "name" ~~* '%test%') OR > "contract" IN (SELECT "ID" FROM "contracts" WHERE "name" ~~* '%test%') > This yields the following pla

Re: Unclamped row estimates whith OR-ed subplans

2020-06-19 Thread Laurenz Albe
On Fri, 2020-06-19 at 17:12 +0200, Benjamin Coutu wrote: > please consider the following SQL query: > > SELECT * FROM "transactions" WHERE > "account" IN (SELECT "ID" FROM "accounts" WHERE "name" ~~* '%test%') > OR > "contract" IN (SELECT "ID" FROM "contracts" WHERE "name" ~~* '%