Re: Bad row estimation with indexed func returning bool

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jehan-Guillaume de Rorthais <jgdr(at)dalibo(dot)com>
Cc: Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Bad row estimation with indexed func returning bool
Date: 2015-09-23 23:30:17
Message-ID: 4874.1443051017@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> However, in the case at hand, the complaint basically is why aren't we
> treating the boolean function expression like a boolean variable, and
> looking to see if there are stats available for it, like this other
> bit in clause_selectivity:

> /*
> * A Var at the top of a clause must be a bool Var. This is
> * equivalent to the clause reln.attribute = 't', so we compute
> * the selectivity as if that is what we have.
> */
> s1 = restriction_selectivity(root,
> BooleanEqualOperator,
> list_make2(var,
> makeBoolConst(true,
> false)),
> InvalidOid,
> varRelid);

> Indeed you could argue that this ought to be the fallback behavior for
> *any* unhandled case, not just function expressions. Not sure if we'd
> need to restrict it to single-relation expressions or not.

> The implication of doing it like this would be that the default estimate
> in the absence of any matching stats would be 0.5 (since eqsel defaults
> to 1/ndistinct, and get_variable_numdistinct will report 2.0 for any
> boolean-type expression it has no stats for). That's not a huge change
> from the existing 0.3333333 estimate, which seems pretty unprincipled
> anyway ... but it would probably be enough to annoy people if we did it in
> stable branches. So I'd be inclined to propose changing this in HEAD and
> maybe 9.5, but not further back. (For non-function expressions, 0.5 is
> the default already, so those would not change behavior.)

I experimented with the attached patch. The change in the default
estimate for a function results in just one change in the standard
regression test results, so far as I can find.

Comments, objections?

regards, tom lane

Attachment Content-Type Size
look-for-stats-for-bool-functions.patch text/x-diff 6.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Josh Berkus 2015-09-23 23:33:33 Re: No Issue Tracker - Say it Ain't So!
Previous Message Tom Lane 2015-09-23 23:25:24 Re: clearing opfuncid vs. parallel query