Re: Cache lookup errors with functions manipulation object addresses
Michael Paquier <michael@paquier.xyz>
From: Michael Paquier <michael@paquier.xyz>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Andrew Dunstan <andrew.dunstan@2ndquadrant.com>, pgsql-hackers@lists.postgresql.org
Date: 2018-12-13T05:55:07Z
Lists: pgsql-hackers
Attachments
- 0001-Introduce-new-extended-routines-for-FDW-and-foreign-.patch (text/x-diff) patch 0001
- 0002-Eliminate-user-visible-cache-lookup-errors-for-objad.patch.gz (application/gzip) patch 0002
On Wed, Dec 12, 2018 at 02:21:29PM -0300, Alvaro Herrera wrote:
> I think defining bit flags in an enum is weird; I'd use defines
> instead.
Okay, I am fine with that.
> And (a purely stylistic point) I'd use bits32 rather than uint32. (I'm
> probably alone in this opinion, since almost every interface passing
> flags uses unsigned int of some size. But "bits" types are defined
> precisely for this purpose!) Compare a61f5ab98638.
Fine with that as well, let's do as you suggest then.
> I support 0001 other than those two points.
Attached is an updated version for that as 0001. Thanks for the
review. Does that part look good to you now?
> Yeah, these two cases:
>
> +-- Keep those checks in the same order as getObjectTypeDescription()
> +SELECT * FROM pg_identify_object_as_address('pg_class'::regclass, 0, 0); -- no relation
> + type | object_names | object_args
> +------+--------------+-------------
> + | |
> +(1 row)
"type" should show "relation" here, yes.
> +SELECT * FROM pg_identify_object_as_address('pg_proc'::regclass, 0, 0); -- no function
> + type | object_names | object_args
> +------+--------------+-------------
> + | {} | {}
> +(1 row)
>
> All the other cases you add have a non-empty value in "type".
On this one I would expect NULL for object_names and object_args, as
empty does not make sense for an undefined object, still "type" should
print... "type".
+SELECT * FROM pg_identify_object_as_address('pg_constraint'::regclass, 0, 0); -- no constraint
+ type | object_names | object_args
+------+--------------+-------------
+ | |
+(1 row)
Constraints also are empty.
+SELECT * FROM pg_identify_object_as_address('pg_largeobject'::regclass, 0, 0); -- no large object, no error
+ type | object_names | object_args
+--------------+--------------+-------------
+ large object | {0} | {}
+(1 row)
Large objects should return NULL for the last two fields.
There are a couple of other inconsistent cases with the existing sub-APIs:
+SELECT * FROM pg_identify_object_as_address('pg_type'::regclass, 0, 0); -- no type
+ type | object_names | object_args
+------+--------------+-------------
+ type | {-} | {}
+(1 row)
Here I would expect NULL for object_names and object_args.
> I think this is our chance to fix the mess. Previously (before I added
> the SQL-access of the object addressing mechanism in 9.5 I mean) it
> wasn't possible to get at this code at all with arbitrary input, so this
> is all a "new" problem (I mean new in the last 5 years).
This requires a bit more work with the low-level APIs grabbing the
printed information though. And I think that the following guidelines
make sense to work on as a base definition for undefined objects:
- pg_identify_object returns the object type name, NULL for the other fields.
- pg_describe_object returns just NULL.
- pg_identify_object_as_address returns the object type name and NULL
for the other fields.
There is some more refactoring work still needed for constraints, large
objects and functions, in a way similar to a26116c6. I am pretty happy
with the shape of 0001, so this could be applied, 0002 still needs to be
reworked so as all undefined object types behave as described above in a
consistent manner. Do those definitions make sense?
--
Michael
Commits
-
Eliminate cache lookup errors in SQL functions for object addresses
- 2a10fdc4307a 14.0 landed
-
Refactor routines for name lookups of procedures and operators
- aa38434824c4 14.0 landed
-
Add new flag to format_type_extended() to get NULL for undefined type
- 1185c782943c 14.0 landed
-
Introduce new extended routines for FDW and foreign server lookups
- 8fb569e978af 12.0 landed
-
Refactor routines for subscription and publication lookups
- 1d6fbc38d9ed 12.0 landed
-
get_relid_attribute_name is dead, long live get_attname
- 8237f27b504f 11.0 landed
-
Tweak parser so that there is a defined representation for datatypes
- a585c20d12d0 7.2.1 cited