pgsql: Mark built-in btree comparison functions as leakproof where it's

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Mark built-in btree comparison functions as leakproof where it's
Date: 2018-07-11 22:47:40
Message-ID: E1fdNtc-00031T-Ns@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Mark built-in btree comparison functions as leakproof where it's safe.

Generally, if the comparison operators for a datatype or pair of datatypes
are leakproof, the corresponding btree comparison support function can be
considered so as well. But we had not originally worried about marking
support functions as leakproof, reasoning that they'd not likely be used in
queries so the marking wouldn't matter. It turns out there's at least one
place where it does matter: calc_arraycontsel() finds the target datatype's
default btree comparison function and tries to use that to estimate
selectivity, but it will be blocked in some cases if the function isn't
leakproof. This leads to unnecessarily poor selectivity estimates and bad
plans, as seen in bug #15251.

Hence, run around and apply proleakproof markings where the corresponding
btree comparison operators are leakproof. (I did eyeball each function
to verify that it wasn't doing anything surprising, too.)

This isn't a full solution to bug #15251, and it's not back-patchable
because of the need for a catversion bump. A more useful response probably
is to consider whether we can check permissions on the parent table instead
of the child. However, this change will help in some cases where that
won't, and it's easy enough to do in HEAD, so let's do so.

Discussion: https://postgr.es/m/3876.1531261875@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/39a96512b3ed72de7b24b2667d9575d7e9fcb326

Modified Files
--------------
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_proc.dat | 116 +++++++++++++++----------------
src/test/regress/expected/opr_sanity.out | 35 ++++++++++
3 files changed, 94 insertions(+), 59 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Geoghegan 2018-07-11 23:35:33 Re: Tips on committing
Previous Message Tom Lane 2018-07-11 19:25:46 pgsql: Fix create_scan_plan's handling of sortgrouprefs for physical tl