Re: making EXPLAIN extensible - Mailing list pgsql-hackers
From | Thom Brown |
---|---|
Subject | Re: making EXPLAIN extensible |
Date | |
Msg-id | CAA-aLv4MDS2aQLR9v5xgg9qiN7z_YrbcYf-FGWVCN=Jv_Psppg@mail.gmail.com Whole thread Raw |
In response to | making EXPLAIN extensible (Robert Haas <robertmhaas@gmail.com>) |
Responses |
Re: making EXPLAIN extensible
Re: making EXPLAIN extensible |
List | pgsql-hackers |
On Fri, 28 Feb 2025 at 19:26, Robert Haas <robertmhaas@gmail.com> wrote: > > Prior to PostgreSQL 10, EXPLAIN had just 2 options: VACUUM and > ANALYZE. Now, we're up to 12 options, which is already quite a lot, > and there's plenty more things that somebody might like to do. > However, not all of those things necessarily need to be part of the > core code. My original reason for wanting to extend EXPLAIN was that I > was thinking about an extension that would want to do a bunch of > things and one of those things would be to add some information to the > EXPLAIN output. It wouldn't make sense for core to have an EXPLAIN > option whose whole purpose is to cater to the needs of some extension, > so that made me think of providing some extensibility infrastructure. > > However, there are other use cases, too, basically any of the normal > reasons why extensibility is useful and desirable. You might need to > get some information out a query plan that 99% of people don't care > about. You could come up with your own way of formatting a query plan, > but that's a big pain. It's a lot nicer if you can just add the detail > that you care about to the EXPLAIN output without needing to modify > PostgreSQL itself. Even if you think of something that really ought to > be included in the EXPLAIN output by PostgreSQL, you can roll an > extension out much quicker than you can get a change upstreamed and > released. So I think EXPLAIN extensibility is, as a general concept, > useful. > > So here are some patches. > > 0001 allows a loadable module to register new EXPLAIN options. > Currently, EXPLAIN (FUNGUS) will error out, but if you want to make it > work, this patch is for you. This patch also allows you to stash some > state related to your new option, or options, in the ExplainState. > Core options have hard-coded structure members; e.g. EXPLAIN (BUFFERS) > sets es->buffers. If you add EXPLAIN (FUNGUS), there won't be an > es->fungus, but you can get about the same effect using the new > facilities provided here. > > 0002 provides hooks that you can use to make your new EXPLAIN options > actually do something. In particular, this adds a new hook that is > called once per PlanState node, and a new nook that is called once per > PlannedStmt. Each is called at an appropriate point for you to tack on > more output after what EXPLAIN would already produce. > > 0003 adds a new contrib module called pg_overexplain, which adds > EXPLAIN (DEBUG) and EXPLAIN (RANGE_TABLE). I actually think this is > quite useful for planner hacking, and maybe a few more options would > be, too. Right now, if you want to see stuff that EXPLAIN doesn't > clearly show, you have to use SET debug_print_plan = true, and that > output is so verbose that finding the parts you actually want to see > is quite difficult. Assuming it gives you the details you need, > EXPLAIN (RANGE_TABLE) looks way, way better to me, and if we end up > committing these patches I anticipate using this semi-regularly. > > There are plenty of debatable things in this patch set, and I mention > some of them in the commit messages. The hook design in 0002 is a bit > simplistic and could be made more complex; there's lots of stuff that > could be added to or removed from 0003, much of which comes down to > what somebody hacking on the planner would actually want to see. I'm > happy to bikeshed all of that stuff; this is all quite preliminary and > I'm not committed to the details. The only thing that would disappoint > me is if somebody said "this whole idea of making EXPLAIN extensible > is stupid and pointless and we shouldn't ever do it." I will argue > against that vociferously. I think even what I have here is enough to > disprove that hypothesis, but I have a bunch of ideas about how to do > more. Some of those require additional infrastructure and are best > proposed with that other infrastructure; some can be done with just > this, but I ran out of time to code up examples so here is what I have > got so far. > > Hope you like it, sorry if you don't. "pg_overexplain"? I love this name! And the idea sounds like a natural evolution, so +1. Some questions: One thing I am wondering is whether extensions should be required to prefix their EXPLAIN option with the extension name to avoid collisions. If two extensions happen to choose the same name, it won't be possible to use both simultaneously. In what order would the options be applied? Would it be deterministic, or weighted within the extension's configuration, or based on the order of the options in the list? Would explain extensions be capable of modifying pre-existing core option output, or just append to output? Should there be a way of determining which lines are output by which option? An extension may output similar output to core output, making it difficult or impossible to discern which is which. Does there need to be any security considerations so that things like RLS don't inadvertently become leaky? Thom
pgsql-hackers by date: