Allowing extensions to find out the OIDs of their member objects - Mailing list pgsql-hackers
From | Tom Lane |
---|---|
Subject | Allowing extensions to find out the OIDs of their member objects |
Date | |
Msg-id | 15289.1548028233@sss.pgh.pa.us Whole thread Raw |
Responses |
Re: Allowing extensions to find out the OIDs of their member objects
Re: Allowing extensions to find out the OIDs of their member objects Re: Allowing extensions to find out the OIDs of their member objects Re: Allowing extensions to find out the OIDs of their member objects Re: Allowing extensions to find out the OIDs of their member objects Re: Allowing extensions to find out the OIDs of their member objects |
List | pgsql-hackers |
In [1] I propose that we should allow extensions to get their hands on the ability to transform function calls as per "protransform" and to generate lossy index quals based on items in WHERE clauses. The APIs to give an extension control at the right points seem pretty straightforward, but there's a problem standing in the way of actually doing anything useful once you've got control. In order to either analyze a passed-in clause or generate a new one, the extension will need to know the OIDs of the functions/operators it's working with. And extension objects don't have fixed OIDs. In principle this could be dealt with by looking up said OIDs from the catalogs, but that's (1) complicated, (2) slow, (3) prone to possibly-security-sensitive mistakes such as omitting a schema specification, and (4) at risk of getting broken entirely by user-accessible changes such as ALTER FUNCTION RENAME. Point (2) can be alleviated by caching, but that just makes (1) even worse, plus there are lots of ways to do caching wrong. I thought about extending the extension infrastructure to provide some way of retrieving relevant OIDs. We could imagine, for instance, that an extension script has a way to say "this function is object number three within this extension", and while running the script we make a catalog entry showing that object number three has OID thus-and-so, and then that catalog entry can be consulted to get the right OID (by C code that has hard-wired knowledge that object number three is the function it cares about). This is still kind of messy, because aside from the hand-assigned object numbers you'd have to use the extension name as part of the lookup key, making the name into something the C code critically depends on. We don't have ALTER EXTENSION RENAME, so maybe that's okay, but it seems painful to say that we can never have it. In the end it seems like possibly the cleanest answer is to change things so that extensions *can* have fixed OIDs that their C code can know, eliminating lookup costs and allowing coding conventions for this sort of work to be the same as in the core backend. We could raise FirstNormalObjectId to create some unused OID space that we could then assign chunks of to specific extensions on-request. This is problematic for relations, types, and roles, because pg_upgrade wants to preserve OIDs of those objects across upgrades, so we could not ensure that the "unused" space is free of such objects. But it would work for all other object types, and I think that it might well be sufficient if an extension can have fixed OIDs for its functions, operators, and opfamilies/opclasses. (At need, it could find out the OID for one of its types by looking up the argument or result types for one of its functions.) There are various places in pg_upgrade and postgres_fdw that assume more than they perhaps should about the significance of FirstNormalObjectId, but I think that that could be dealt with. A larger issue is whether "hand out some OIDs on-demand" is a sustainable strategy. I think that it is, if we encourage extensions to assign fixed OIDs only to objects they really need to. In thirty-ish years of core PG development, we've only used up ~4200 fixed OIDs, and a lot of those are for functions that probably don't really need fixed OIDs but got one because we give one to every built-in function. However, if there's a big land rush to claim large chunks of OIDs, we might have a problem. We'd have to invent some SQL syntax whereby extension scripts can actually apply their assigned OIDs to their objects. I'm not very enthused about adding an "OID nnn" option to every type of CREATE command that might need this. A quick-and-dirty answer is to create support functions similar to binary_upgrade_set_next_pg_type_oid() that set the OID to give to the next-created object of each category we need to support. There are various issues and bits of work around this, but the only one that I've thought of that I haven't got an answer for is "how should an extension upgrade script assign a fixed OID to an object that already existed in the previous extension version, but without a fixed OID?". We can't just change the recorded OID because that'll break dependencies, view references, etc. Conceivably we could write code that runs through the catalogs and changes all references, but man that'd be a mess. Anyone have another idea? Another question is whether you need any special permissions to assign a fixed OID in this way. The most conservative answer is to require superuserness, which might be enough because the plausible use-cases for fixed OIDs involve C code, which you'd need to be superuser to install anyhow. But it seems overkill somehow. OTOH, it would be annoying if a random user could eat up a "reserved" OID that later prevented someone from installing an extension they wanted. Thoughts? regards, tom lane [1] https://www.postgresql.org/message-id/15193.1548028093@sss.pgh.pa.us
pgsql-hackers by date: