Re: Allowing extensions to supply operator-/function-specific info
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2019-01-24T02:39:18Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Allow extensions to generate lossy index conditions.
- 74dfe58a5927 12.0 landed
-
Build out the planner support function infrastructure.
- a391ff3c3d41 12.0 landed
-
Create the infrastructure for planner support functions.
- 1fb57af92069 12.0 landed
-
Disable transforms that replaced AT TIME ZONE with RelabelType.
- c22ecc6562aa 10.0 cited
Attachments
- v1-0001-change-protransform-API-review.patch (text/x-diff) patch v1-0001
- v1-0001-change-protransform-API-apply.patch (text/x-diff) patch v1-0001
- v1-0002-add-sql-support.patch (text/x-diff) patch v1-0002
- v1-0003-add-selectivity-etc.patch (text/x-diff) patch v1-0003
I wrote: > What I'm envisioning therefore is that we allow an auxiliary function to > be attached to any operator or function that can provide functionality > like this, and that we set things up so that the set of tasks that > such functions can perform can be extended over time without SQL-level > changes. Here are some draft patches in pursuit of this goal. 0001 redefines the API for protransform functions, renames that pg_proc column to prosupport, and likewise renames the existing transform functions to be xxx_support. There are no actual functionality changes in this step. I needed to reindent the existing code in the transform functions, so for ease of review, the -review patch uses "git diff -b" to suppress most of the reindentation diffs. If you want to actually apply the patch for testing, use the -apply version. Possibly worth noting is that I chose to just remove timestamp_zone_transform and timestamp_izone_transform, rather than change them from one no-op state to another. We left them in place in commit c22ecc656 to avoid a catversion bump, but that argument no longer applies, and there seems little likelihood that we'll need them soon. 0002 adds the ability to attach a support function via CREATE/ALTER FUNCTION, and adds the necessary pg_dump and ruleutils support for that. The only thing that's not pretty mechanical about that is that ALTER FUNCTION needs the ability to replace a dependency on a previous support function. For that, we should use changeDependencyFor() ... but there's a problem, which is that that function can't cope with the case where the existing dependency is on a pinned object. We'd left that unimplemented, arguing that it wasn't really necessary for the existing usage of that function to change schema dependencies. But it seems fairly likely that the case would occur for support functions, so I went ahead and fixed changeDependencyFor() to handle it. That leads to a change in the alter_table regression test, which was pedantically verifying that the limitation existed. (We could alternatively leave out the ability to set this option in ALTER FUNCTION, requiring people to use CREATE OR REPLACE FUNCTION for it. But I'm figuring that extension update scripts will want to add support functions to existing functions, so it'd be tedious to not be able to do it with a simple ALTER.) 0003 is where something useful happens. It extends the API to allow support functions to define the selectivity estimates, cost estimates, and rowcount estimates (for set-returning functions) of their target functions. I can't overstate how important this is: it's retiring technical debt that has been there for decades. As proof of concept, there is a quick hack in the regression tests that teaches the planner to make accurate rowcount estimates for generate_series(int, int) with constant or estimatable arguments. There's a considerable amount of follow-up work that ought to happen now to make use of these capabilities for places that have been pain points in the past, such as generate_series() and unnest(). But I haven't touched that yet. Still to be done is to provide an API responding to Paul's original problem, i.e. allowing an extension to generate lossy index clauses when one of its operators or functions appears in WHERE. That's going to be more complex than 0003 --- for one thing, I think I'd like to try to refactor the existing hard-wired cases in indxpath.c so that they live in datatype-specific support functions instead of the core index code. But first, I'd like to push forward with committing what I've got. I think this is pretty damn compelling already, even if nothing further got done for v12. Is anybody interested in reviewing? regards, tom lane