making EXPLAIN extensible - Mailing list pgsql-hackers
From | Robert Haas |
---|---|
Subject | making EXPLAIN extensible |
Date | |
Msg-id | CA+TgmoYSzg58hPuBmei46o8D3SKX+SZoO4K_aGQGwiRzvRApLg@mail.gmail.com Whole thread Raw |
Responses |
Re: making EXPLAIN extensible
Re: making EXPLAIN extensible Re: making EXPLAIN extensible Re: making EXPLAIN extensible Re: making EXPLAIN extensible Re: making EXPLAIN extensible |
List | pgsql-hackers |
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. -- Robert Haas EDB: http://www.enterprisedb.com
Attachment
pgsql-hackers by date: