How about to have relnamespace and relrole?
Hello,
Most of OID types has reg* OID types. Theses are very convenient
when looking into system catalog/views, but there aren't OID
types for userid and namespace id.
What do you think about having these new OID types? The
usefulness of regnamespace is doubtful but regrole should be
useful because the column like 'owner' appears many places.
For example this works as follows.
====
SELECT relnamespace::regnamespace, relname, relowner::regrole
FROM pg_class WHERE relnamespace = 'public'::regnamespace;
relnamespace | relname | relowner
--------------+---------+----------
public | t1 | horiguti
(1 row)
What do you think about this?
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
0001-Add-regnamespace.patchtext/x-patch; charset=us-asciiDownload
>From cd1137f940aa63c3597e76fd740b05778654d3bb Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 21 Jan 2015 11:38:21 +0900
Subject: [PATCH 1/2] Add regnamespace.
---
doc/src/sgml/datatype.sgml | 19 ++++---
src/backend/utils/adt/regproc.c | 97 +++++++++++++++++++++++++++++++++++
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 10 ++++
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 22 ++++++++
src/test/regress/sql/regproc.sql | 4 ++
8 files changed, 163 insertions(+), 6 deletions(-)
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index edf636b..9799e18 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4422,6 +4422,13 @@ SELECT * FROM pg_attribute
</row>
<row>
+ <entry><type>regnamespace</></entry>
+ <entry><structname>pg_namespace</></entry>
+ <entry>namespace(schema) name</entry>
+ <entry><literal>pg_catalog</></entry>
+ </row>
+
+ <row>
<entry><type>regtype</></entry>
<entry><structname>pg_type</></entry>
<entry>data type name</entry>
@@ -4446,12 +4453,12 @@ SELECT * FROM pg_attribute
</table>
<para>
- All of the OID alias types accept schema-qualified names, and will
- display schema-qualified names on output if the object would not
- be found in the current search path without being qualified.
- The <type>regproc</> and <type>regoper</> alias types will only
- accept input names that are unique (not overloaded), so they are
- of limited use; for most uses <type>regprocedure</> or
+ All of the OID alias types except regnamespace accept schema-qualified
+ names, and will display schema-qualified names on output if the object
+ would not be found in the current search path without being qualified.
+ The <type>regproc</> and <type>regoper</> alias types will only accept
+ input names that are unique (not overloaded), so they are of limited use;
+ for most uses <type>regprocedure</> or
<type>regoperator</> are more appropriate. For <type>regoperator</>,
unary operators are identified by writing <literal>NONE</> for the unused
operand.
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 3d1bb32..b09aa2a 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -1159,6 +1159,103 @@ regclasssend(PG_FUNCTION_ARGS)
/*
+ * regnamespacein - converts "classname" to class OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_class entry.
+ */
+Datum
+regnamespacein(PG_FUNCTION_ARGS)
+{
+ char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
+ Oid result = InvalidOid;
+
+ /* '-' ? */
+ if (strcmp(nsp_name_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (nsp_name_or_oid[0] >= '0' &&
+ nsp_name_or_oid[0] <= '9' &&
+ strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(nsp_name_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /* Else it's a name */
+
+ result = get_namespace_oid(nsp_name_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regnamespace - converts "nspname" to namespace OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regnamespace(PG_FUNCTION_ARGS)
+{
+ char *nsp_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_namespace_oid(nsp_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regnamespaceout - converts namespace OID to "nspname"
+ */
+Datum
+regnamespaceout(PG_FUNCTION_ARGS)
+{
+ Oid nspid = PG_GETARG_OID(0);
+ char *result;
+
+ if (nspid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = get_namespace_name(nspid);
+ if (result)
+ PG_RETURN_CSTRING(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regnamespacerecv - converts external binary format to regnamespace
+ */
+Datum
+regnamespacerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regnamespacesend - converts regnamespace to binary format
+ */
+Datum
+regnamespacesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
+
+
+/*
* regtypein - converts "typename" to type OID
*
* We also accept a numeric OID, for symmetry with the output routine.
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index b314369..e4b24e3 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -210,6 +210,13 @@ DATA(insert ( 3769 20 1288 a f ));
DATA(insert ( 3769 23 0 a b ));
DATA(insert ( 25 2205 1079 i f ));
DATA(insert ( 1043 2205 1079 i f ));
+DATA(insert ( 26 4089 0 i b ));
+DATA(insert ( 4089 26 0 i b ));
+DATA(insert ( 20 4089 1287 i f ));
+DATA(insert ( 21 4089 313 i f ));
+DATA(insert ( 23 4089 0 i b ));
+DATA(insert ( 4089 20 1288 a f ));
+DATA(insert ( 4089 23 0 a b ));
/*
* String category
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 9edfdb8..cd6dbcf 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3435,7 +3435,13 @@ DATA(insert OID = 3493 ( to_regtype PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2
DESCR("convert type name to regtype");
DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "25" _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ ));
DESCR("convert text to regclass");
+DATA(insert OID = 4084 ( regnamespacein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ regnamespacein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4085 ( regnamespaceout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4089" _null_ _null_ _null_ _null_ regnamespaceout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4086 ( to_regnamespace PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ to_regnamespace _null_ _null_ _null_ ));
+DESCR("convert namespace name to regnamespace");
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
DESCR("(internal)");
DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
@@ -3831,6 +3837,10 @@ DATA(insert OID = 2454 ( regtyperecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1
DESCR("I/O");
DATA(insert OID = 2455 ( regtypesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2206" _null_ _null_ _null_ _null_ regtypesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4087 ( regnamespacerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4089 "2281" _null_ _null_ _null_ _null_ regnamespacerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4088 ( regnamespacesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4089" _null_ _null_ _null_ _null_ regnamespacesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 0a900dd..4aae8b6 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -564,12 +564,17 @@ DATA(insert OID = 2206 ( regtype PGNSP PGUID 4 t b N f t \054 0 0 2211 regty
DESCR("registered type");
#define REGTYPEOID 2206
+DATA(insert OID = 4089 ( regnamespace PGNSP PGUID 4 t b N f t \054 0 0 4090 regnamespacein regnamespaceout regnamespacerecv regnamespacesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered namespace");
+#define REGNAMESPACEOID 4089
+
DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
+DATA(insert OID = 4090 ( _regnamespace PGNSP PGUID -1 f b A f t \054 0 4089 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index bc4517d..14b1896 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -630,6 +630,11 @@ extern Datum regtypeout(PG_FUNCTION_ARGS);
extern Datum regtyperecv(PG_FUNCTION_ARGS);
extern Datum regtypesend(PG_FUNCTION_ARGS);
extern Datum to_regtype(PG_FUNCTION_ARGS);
+extern Datum regnamespacein(PG_FUNCTION_ARGS);
+extern Datum regnamespaceout(PG_FUNCTION_ARGS);
+extern Datum regnamespacerecv(PG_FUNCTION_ARGS);
+extern Datum regnamespacesend(PG_FUNCTION_ARGS);
+extern Datum to_regnamespace(PG_FUNCTION_ARGS);
extern Datum regconfigin(PG_FUNCTION_ARGS);
extern Datum regconfigout(PG_FUNCTION_ARGS);
extern Datum regconfigrecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index 3342129..44166a2 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -39,6 +39,12 @@ SELECT regtype('int4');
integer
(1 row)
+SELECT regnamespace('pg_catalog');
+ regnamespace
+--------------
+ pg_catalog
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -75,6 +81,12 @@ SELECT to_regtype('int4');
integer
(1 row)
+SELECT to_regnamespace('pg_catalog');
+ to_regnamespace
+-----------------
+ pg_catalog
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -168,6 +180,10 @@ SELECT regtype('int3');
ERROR: type "int3" does not exist
LINE 1: SELECT regtype('int3');
^
+SELECT regnamespace('nonexistent');
+ERROR: schema "nonexistent" does not exist
+LINE 1: SELECT regnamespace('nonexistent');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -231,6 +247,12 @@ SELECT to_regtype('int3');
(1 row)
+SELECT to_regnamespace('nonexistent');
+ to_regnamespace
+-----------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index cc90838..04eed63 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -12,6 +12,7 @@ SELECT regproc('now');
SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
+SELECT regnamespace('pg_catalog');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -19,6 +20,7 @@ SELECT to_regproc('now');
SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
+SELECT to_regnamespace('pg_catalog');
-- with schemaname
@@ -45,6 +47,7 @@ SELECT regproc('know');
SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
+SELECT regnamespace('nonexistent');
-- with schemaname
@@ -65,6 +68,7 @@ SELECT to_regproc('know');
SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
+SELECT to_regnamespace('nonexistent');
-- with schemaname
--
2.1.0.GIT
0002-Add-regrole.patchtext/x-patch; charset=us-asciiDownload
>From 8c817e8de4ce7f8a97e9e3298b72e05bea1ba1ea Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 21 Jan 2015 13:22:12 +0900
Subject: [PATCH 2/2] Add regrole.
---
doc/src/sgml/datatype.sgml | 19 +++++--
src/backend/utils/adt/regproc.c | 101 ++++++++++++++++++++++++++++++++++
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 11 +++-
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 26 ++++++++-
src/test/regress/sql/regproc.sql | 7 +++
8 files changed, 173 insertions(+), 8 deletions(-)
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index 9799e18..411771e 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4448,17 +4448,24 @@ SELECT * FROM pg_attribute
<entry>text search dictionary</entry>
<entry><literal>simple</></entry>
</row>
+
+ <row>
+ <entry><type>regrole</></entry>
+ <entry><structname>pg_role</></entry>
+ <entry>role name</entry>
+ <entry><literal>user1</></entry>
+ </row>
</tbody>
</tgroup>
</table>
<para>
- All of the OID alias types except regnamespace accept schema-qualified
- names, and will display schema-qualified names on output if the object
- would not be found in the current search path without being qualified.
- The <type>regproc</> and <type>regoper</> alias types will only accept
- input names that are unique (not overloaded), so they are of limited use;
- for most uses <type>regprocedure</> or
+ All of the OID alias types except regnamespace and regrole accept
+ schema-qualified names, and will display schema-qualified names on output
+ if the object would not be found in the current search path without being
+ qualified. The <type>regproc</> and <type>regoper</> alias types will
+ only accept input names that are unique (not overloaded), so they are of
+ limited use; for most uses <type>regprocedure</> or
<type>regoperator</> are more appropriate. For <type>regoperator</>,
unary operators are identified by writing <literal>NONE</> for the unused
operand.
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index b09aa2a..6155e4f 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -40,6 +40,7 @@
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/tqual.h"
+#include "utils/acl.h"
static char *format_operator_internal(Oid operator_oid, bool force_qualify);
static char *format_procedure_internal(Oid procedure_oid, bool force_qualify);
@@ -1650,6 +1651,106 @@ regdictionarysend(PG_FUNCTION_ARGS)
return oidsend(fcinfo);
}
+/*
+ * regrolein - converts "regrole" to role OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_ts_dict entry.
+ *
+ * This function is not needed in bootstrap mode, so we don't worry about
+ * making it work then.
+ */
+Datum
+regrolein(PG_FUNCTION_ARGS)
+{
+ char *role_or_oid = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ /* '-' ? */
+ if (strcmp(role_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (role_or_oid[0] >= '0' &&
+ role_or_oid[0] <= '9' &&
+ strspn(role_or_oid, "0123456789") == strlen(role_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(role_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /*
+ * Normal case: parse the name into components and see if it matches any
+ * pg_role entries in the current search path.
+ */
+ result = get_role_oid(role_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regrole - converts "role name" to role OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regrole(PG_FUNCTION_ARGS)
+{
+ char *role_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_role_oid(role_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regroleout - converts role OID to "role_name"
+ */
+Datum
+regroleout(PG_FUNCTION_ARGS)
+{
+ Oid roleoid = PG_GETARG_OID(0);
+ char *result;
+
+
+ if (roleoid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = GetUserNameFromId(roleoid);
+ PG_RETURN_CSTRING(result);
+}
+
+/*
+ * regrolerecv - converts external binary format to regrole
+ */
+Datum
+regrolerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regrolesend - converts regrole to binary format
+ */
+Datum
+regrolesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
+
+
/*
* text_regclass: convert text to regclass
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index e4b24e3..fad168f 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -217,6 +217,13 @@ DATA(insert ( 21 4089 313 i f ));
DATA(insert ( 23 4089 0 i b ));
DATA(insert ( 4089 20 1288 a f ));
DATA(insert ( 4089 23 0 a b ));
+DATA(insert ( 26 4096 0 i b ));
+DATA(insert ( 4096 26 0 i b ));
+DATA(insert ( 20 4096 1287 i f ));
+DATA(insert ( 21 4096 313 i f ));
+DATA(insert ( 23 4096 0 i b ));
+DATA(insert ( 4096 20 1288 a f ));
+DATA(insert ( 4096 23 0 a b ));
/*
* String category
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index cd6dbcf..9787d33 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3437,11 +3437,16 @@ DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 22
DESCR("convert text to regclass");
DATA(insert OID = 4084 ( regnamespacein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ regnamespacein _null_ _null_ _null_ ));
DESCR("I/O");
-
DATA(insert OID = 4085 ( regnamespaceout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4089" _null_ _null_ _null_ _null_ regnamespaceout _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 4086 ( to_regnamespace PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ to_regnamespace _null_ _null_ _null_ ));
DESCR("convert namespace name to regnamespace");
+DATA(insert OID = 4091 ( regrolein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ regrolein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4096" _null_ _null_ _null_ _null_ regroleout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
+DESCR("convert role name to regrole");
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
DESCR("(internal)");
DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
@@ -3841,6 +3846,10 @@ DATA(insert OID = 4087 ( regnamespacerecv PGNSP PGUID 12 1 0 0 0 f f f f t f
DESCR("I/O");
DATA(insert OID = 4088 ( regnamespacesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4089" _null_ _null_ _null_ _null_ regnamespacesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4096 "2281" _null_ _null_ _null_ _null_ regrolerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 4aae8b6..0bd3fbd 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -568,6 +568,10 @@ DATA(insert OID = 4089 ( regnamespace PGNSP PGUID 4 t b N f t \054 0 0 4090 re
DESCR("registered namespace");
#define REGNAMESPACEOID 4089
+DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 regrolein regroleout regrolerecv regrolesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered role");
+#define REGROLEOID 4096
+
DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
@@ -575,6 +579,7 @@ DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 arr
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
DATA(insert OID = 4090 ( _regnamespace PGNSP PGUID -1 f b A f t \054 0 4089 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
+DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 14b1896..a95ed23 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -635,6 +635,11 @@ extern Datum regnamespaceout(PG_FUNCTION_ARGS);
extern Datum regnamespacerecv(PG_FUNCTION_ARGS);
extern Datum regnamespacesend(PG_FUNCTION_ARGS);
extern Datum to_regnamespace(PG_FUNCTION_ARGS);
+extern Datum regrolein(PG_FUNCTION_ARGS);
+extern Datum regroleout(PG_FUNCTION_ARGS);
+extern Datum regrolerecv(PG_FUNCTION_ARGS);
+extern Datum regrolesend(PG_FUNCTION_ARGS);
+extern Datum to_regrole(PG_FUNCTION_ARGS);
extern Datum regconfigin(PG_FUNCTION_ARGS);
extern Datum regconfigout(PG_FUNCTION_ARGS);
extern Datum regconfigrecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index 44166a2..479a964 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -2,6 +2,7 @@
-- regproc
--
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
regoper
@@ -45,6 +46,12 @@ SELECT regnamespace('pg_catalog');
pg_catalog
(1 row)
+SELECT regrole('regtestrole');
+ regrole
+-------------
+ regtestrole
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -87,6 +94,12 @@ SELECT to_regnamespace('pg_catalog');
pg_catalog
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+-------------
+ regtestrole
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -155,10 +168,11 @@ SELECT to_regtype('pg_catalog.int4');
(1 row)
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
-- without schemaname
SELECT regoper('||//');
ERROR: operator does not exist: ||//
-LINE 3: SELECT regoper('||//');
+LINE 1: SELECT regoper('||//');
^
SELECT regoperator('++(int4,int4)');
ERROR: operator does not exist: ++(int4,int4)
@@ -184,6 +198,10 @@ SELECT regnamespace('nonexistent');
ERROR: schema "nonexistent" does not exist
LINE 1: SELECT regnamespace('nonexistent');
^
+SELECT regrole('regtestrole');
+ERROR: role "regtestrole" does not exist
+LINE 1: SELECT regrole('regtestrole');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -253,6 +271,12 @@ SELECT to_regnamespace('nonexistent');
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index 04eed63..9a9a44d 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -4,6 +4,7 @@
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
@@ -13,6 +14,7 @@ SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
SELECT regnamespace('pg_catalog');
+SELECT regrole('regtestrole');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -21,6 +23,7 @@ SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
SELECT to_regnamespace('pg_catalog');
+SELECT to_regrole('regtestrole');
-- with schemaname
@@ -39,6 +42,8 @@ SELECT to_regtype('pg_catalog.int4');
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
+
-- without schemaname
SELECT regoper('||//');
@@ -48,6 +53,7 @@ SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
SELECT regnamespace('nonexistent');
+SELECT regrole('regtestrole');
-- with schemaname
@@ -69,6 +75,7 @@ SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
SELECT to_regnamespace('nonexistent');
+SELECT to_regrole('regtestrole');
-- with schemaname
--
2.1.0.GIT
Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp> writes:
Most of OID types has reg* OID types. Theses are very convenient
when looking into system catalog/views, but there aren't OID
types for userid and namespace id.
What do you think about having these new OID types?
I'm not really excited about that. That line of thought would imply
that we should have "reg*" types for every system catalog, which is
surely overkill.
The existing reg* types were chosen to handle the cases where objects have
schema-qualified (and/or type-overloaded) names so that correct lookup is
not merely a matter of (select oid from pg_foo where name = 'bar') or
vice versa.
I think the policy is, or should be, that we create reg* types for exactly
the cases where lookup isn't that simple.
In particular, both of the cases you mention are hardly "new". They
existed when we made the current set of reg* types and were consciously
not added then.
SELECT relnamespace::regnamespace, relname, relowner::regrole
FROM pg_class WHERE relnamespace = 'public'::regnamespace;
Two reasons this isn't terribly compelling are (1) it's creating a
join in a place where the planner can't possibly see it and optimize
it, and (2) you risk MVCC anomalies because the reg* output routines
would not be using the same snapshot as the calling query.
We already have problem (2) with the existing reg* functions so I'm
not that excited about doubling down on the concept.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Thank you for your comment.
Sorry for the silly typo in the subject.
Tue, 03 Feb 2015 10:12:12 -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote in <2540.1422976332@sss.pgh.pa.us>
Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp> writes:
Most of OID types has reg* OID types. Theses are very convenient
when looking into system catalog/views, but there aren't OID
types for userid and namespace id.What do you think about having these new OID types?
I'm not really excited about that. That line of thought would imply
that we should have "reg*" types for every system catalog, which is
surely overkill.
Mmm. I suppose "for every OID usage", not "every system catalog".
but I agree as the whole. There's no agreeable-by-all
boundary. Perhaps it depends on how often the average DBA looks
onto catalogs which have oids pointing another catalog which they
want to see in human-readable form, without joins if possible.
I very roughly counted how often the oids of catalogs referred
from other catalogs.
As the first step, catalogs which have oid are,
select relname from pg_class where relnamespace = 'pg_catalog'::regnamespace and relhasoids = true;
...
(34 rows)
# Yes, regnamespace is very usable here:)
I say that 34 is too many for sure to have reg* types.
From the viewpoint of human-readable names, the more it enters
DBA's sight, the more significance it could be said to have.
Among the 34, the rough list of from which catalog they are
referred to is following.
pg_authid(role): pg_class, pg_type, pg_database, and many, many.
pg_type: referred to from pg_operator, pg_proc, pg_cast, and many.
pg_namespace: referred to from many catalogs.
pg_class: pg_locks
pg_database: pg_locks
pg_ts_parser: pg_ts_config
pg_ts_template: pg_ts_template
pg_foreign_data_wrapper: pg_foreign_server
pg_foreign_server: pg_user_mapping
This is not an comprehensive counting but I think I can
confidently say that regrole has significant meaning. (and
namespace also could be said so). I would make the comprehensive
one if you or others think it's needed. (altough it would be a
labor)
What do you think about the point of view?
The existing reg* types were chosen to handle the cases where objects have
schema-qualified (and/or type-overloaded) names so that correct lookup is
not merely a matter of (select oid from pg_foo where name = 'bar') or
vice versa.I think the policy is, or should be, that we create reg* types for exactly
the cases where lookup isn't that simple.
Yes, I have noticed that. And I agree that it is one reasonable
boundary. But the point mentioned above is also a reasonable
boundary.
In particular, both of the cases you mention are hardly "new". They
existed when we made the current set of reg* types and were consciously
not added then.SELECT relnamespace::regnamespace, relname, relowner::regrole
FROM pg_class WHERE relnamespace = 'public'::regnamespace;Two reasons this isn't terribly compelling are (1) it's creating a
join in a place where the planner can't possibly see it and optimize
it,
Maybe un-optimiz-ability is not a matter as far as they are used
in one-liners for administrative operations like I mentioned
above. (On the contrary, syscache is far faster than normal table
lookup for most cases, but it doesn't justify to use this in OLTP
jobs even ignoring the MVCC issue.)
and (2) you risk MVCC anomalies because the reg* output routines
would not be using the same snapshot as the calling query.
We already have problem (2) with the existing reg* functions so I'm
not that excited about doubling down on the concept.
Surely. Then the page for the reg* in the doc (datatype-oid.html)
*shoud* mention such a caveat, but the limitation would be
tolerable for user(DBA)s as the same as before.
Once it is stated clearly, althgouh I won't intend to make it an
excuse, I think some (or one) new reg* type can be acceptable.
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello, I changed the subject.
This mail is to address the point at hand, preparing for
registering this commitfest.
15 17:29:14 +0900 (Tokyo Standard Time), Kyotaro HORIGUCHI
<horiguchi.kyotaro@lab.ntt.co.jp> wrote in
<20150204.172914.52110711.horiguchi.kyotaro@lab.ntt.co.jp>
Tue, 03 Feb 2015 10:12:12 -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote in <2540.1422976332@sss.pgh.pa.us>
I'm not really excited about that. That line of thought would imply
that we should have "reg*" types for every system catalog, which is
surely overkill.Mmm. I suppose "for every OID usage", not "every system catalog".
but I agree as the whole. There's no agreeable-by-all
boundary. Perhaps it depends on how often the average DBA looks
onto catalogs which have oids pointing another catalog which they
want to see in human-readable form, without joins if possible.I very roughly counted how often the oids of catalogs referred
from other catalogs.
1. Expected frequency of use
I counted how often oids of system catalogs are referred to by
other system catalog/views. Among them, pg_stat_* views, are
excluded since they have text representations for all oid
references.
The result is like this. The full result of the counting is in
the Excel file but it's not at hand for now.. I'll show it here
if anyone wants to see it.
pg_class.oid: 27
pg_authid.oid: 33
pg_namespace.oid: 20
pg_proc.oid: 13
pg_type.oid: 15
pg_databse.oid: 5
pg_operator.oid: 5
pg_am.oid: 4
....
Among these, authid and namespace are apparently referred to
frequently but don't have their reg* types but referred to from
more points than proc, type, operator, am..
# By the way, I don't understand where the "reg" comes from,
# REGistered? Or other origin?
For that reason, although the current policy of deciding whether
to have reg* types seems to be whether they have schema-qualified
names, I think regrole and regnamespace are valuable to have.
2. Anticipaed un-optimizability
Tom pointed that these reg* types prevents planner from
optimizing the query, so we should refrain from having such
machinary. It should have been a long-standing issue but reg*s
sees to be rather faster than joining corresponding catalogs
for moderate number of the result rows, but this raises another
more annoying issue.
3. Potentially breakage of MVCC
The another issue Tom pointed is potentially breakage of MVCC by
using these reg* types. Syscache is invalidated on updates so
this doesn't seem to be a problem on READ COMMITTED mode, but
breaks SERIALIZABLE mode. But IMHO it is not so serious problem
as long as such inconsistency occurs only on system catalog and
it is explicitly documented togethee with the un-optimizability
issue. I'll add a patch for this later.
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2/12/15 5:28 AM, Kyotaro HORIGUCHI wrote:
Hello, I changed the subject.
This mail is to address the point at hand, preparing for
registering this commitfest.15 17:29:14 +0900 (Tokyo Standard Time), Kyotaro HORIGUCHI
<horiguchi.kyotaro@lab.ntt.co.jp> wrote in
<20150204.172914.52110711.horiguchi.kyotaro@lab.ntt.co.jp>Tue, 03 Feb 2015 10:12:12 -0500, Tom Lane <tgl@sss.pgh.pa.us> wrote in <2540.1422976332@sss.pgh.pa.us>
I'm not really excited about that. That line of thought would imply
that we should have "reg*" types for every system catalog, which is
surely overkill.Mmm. I suppose "for every OID usage", not "every system catalog".
but I agree as the whole. There's no agreeable-by-all
boundary. Perhaps it depends on how often the average DBA looks
onto catalogs which have oids pointing another catalog which they
want to see in human-readable form, without joins if possible.I very roughly counted how often the oids of catalogs referred
from other catalogs.1. Expected frequency of use
...
For that reason, although the current policy of deciding whether
to have reg* types seems to be whether they have schema-qualified
names, I think regrole and regnamespace are valuable to have.
Perhaps schema qualification was the original intent, but I think at
this point everyone uses them for convenience. Why would I want to type
out JOIN pg_namespace n ON n.oid = blah.???namespace when I could simply
do ???namespace::regnamespace?
2. Anticipaed un-optimizability
Tom pointed that these reg* types prevents planner from
optimizing the query, so we should refrain from having such
machinary. It should have been a long-standing issue but reg*s
sees to be rather faster than joining corresponding catalogs
for moderate number of the result rows, but this raises another
more annoying issue.3. Potentially breakage of MVCC
The another issue Tom pointed is potentially breakage of MVCC by
using these reg* types. Syscache is invalidated on updates so
this doesn't seem to be a problem on READ COMMITTED mode, but
breaks SERIALIZABLE mode. But IMHO it is not so serious problem
as long as such inconsistency occurs only on system catalog and
it is explicitly documented togethee with the un-optimizability
issue. I'll add a patch for this later.
The way I look at it, all these arguments went out the window when
regclass was introduced.
The reality is that reg* is *way* more convenient than manual joins. The
arguments about optimization and MVCC presumably apply to all reg*
casts, which means that ship has long since sailed.
If we offered views that made it easier to get at this data then maybe
this wouldn't matter so much. But DBA's don't want to join 3 catalogs
together to try and answer a simple question.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello, thank you for the comment.
The current patch lacks change in documentation and dependency
stuff. Current framework doesn't consider changing pg_shdepend
from column default expressions so the possible measures are the
followings, I think.
1. Make pg_shdepend to have refobjsubid and add some deptypes of
pg_depend, specifically DEPENDENCY_NORMAL is needed. Then,
change the dependency stuff.
2. Simplly inhibit specifying them in default
expressions. Integer or OID can act as the replacement.
=# create table t1 (a int, b regrole default 'horiguti'::regrole);
ERROR: Type 'regrole' cannot have a default value
1 is quite overkill but hardly seems to be usable. So I will go
on 2 and post additional patch.
At Thu, 12 Feb 2015 17:12:24 -0600, Jim Nasby <Jim.Nasby@BlueTreble.com> wrote in <54DD3358.9030601@BlueTreble.com>
On 2/12/15 5:28 AM, Kyotaro HORIGUCHI wrote:
Hello, I changed the subject.
# Ouch! the subject remaines wrong..
1. Expected frequency of use
...
For that reason, although the current policy of deciding whether
to have reg* types seems to be whether they have schema-qualified
names, I think regrole and regnamespace are valuable to have.Perhaps schema qualification was the original intent, but I think at
this point everyone uses them for convenience. Why would I want to
type out JOIN pg_namespace n ON n.oid = blah.???namespace when I could
simply do ???namespace::regnamespace?
Yes, that is the most important point of this patch.
2. Anticipaed un-optimizability
Tom pointed that these reg* types prevents planner from
optimizing the query, so we should refrain from having such
machinary. It should have been a long-standing issue but reg*s
sees to be rather faster than joining corresponding catalogs
for moderate number of the result rows, but this raises another
more annoying issue.3. Potentially breakage of MVCC
The another issue Tom pointed is potentially breakage of MVCC by
using these reg* types. Syscache is invalidated on updates so
this doesn't seem to be a problem on READ COMMITTED mode, but
breaks SERIALIZABLE mode. But IMHO it is not so serious problem
as long as such inconsistency occurs only on system catalog and
it is explicitly documented togethee with the un-optimizability
issue. I'll add a patch for this later.The way I look at it, all these arguments went out the window when
regclass was introduced.The reality is that reg* is *way* more convenient than manual
joins. The arguments about optimization and MVCC presumably apply to
all reg* casts, which means that ship has long since sailed.
I agree basically, but I think some caveat is needed. I'll
include that in the coming documentation patch.
If we offered views that made it easier to get at this data then maybe
this wouldn't matter so much. But DBA's don't want to join 3 catalogs
together to try and answer a simple question.
It has been annoying me these days.
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello, this is the patchset v2 of this feature.
0001-Add-regrole.patch
Adding regrole as the name says.
0002-Add-regnamespace.patch
Adding regnamespace. This depends on 0001 patch.
0003-Check-new-reg-types-are-not-used-as-default-values.patch
Inhibiting the new OID aliss types from being used as constants
in default values, which make dependencies on the other
(existing) OID alias types.
0004-Documentation-for-new-OID-alias-types.patch
Documentation patch for this new types.
regards,
At Tue, 17 Feb 2015 20:19:11 +0900 (Tokyo Standard Time), Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp> wrote in <20150217.201911.239516619.horiguchi.kyotaro@lab.ntt.co.jp>
Hello, thank you for the comment.
The current patch lacks change in documentation and dependency
stuff. Current framework doesn't consider changing pg_shdepend
from column default expressions so the possible measures are the
followings, I think.1. Make pg_shdepend to have refobjsubid and add some deptypes of
pg_depend, specifically DEPENDENCY_NORMAL is needed. Then,
change the dependency stuff.2. Simplly inhibit specifying them in default
expressions. Integer or OID can act as the replacement.=# create table t1 (a int, b regrole default 'horiguti'::regrole);
ERROR: Type 'regrole' cannot have a default value1 is quite overkill but hardly seems to be usable. So I will go
on 2 and post additional patch.At Thu, 12 Feb 2015 17:12:24 -0600, Jim Nasby <Jim.Nasby@BlueTreble.com> wrote in <54DD3358.9030601@BlueTreble.com>
On 2/12/15 5:28 AM, Kyotaro HORIGUCHI wrote:
Hello, I changed the subject.
# Ouch! the subject remaines wrong..
1. Expected frequency of use
...
For that reason, although the current policy of deciding whether
to have reg* types seems to be whether they have schema-qualified
names, I think regrole and regnamespace are valuable to have.Perhaps schema qualification was the original intent, but I think at
this point everyone uses them for convenience. Why would I want to
type out JOIN pg_namespace n ON n.oid = blah.???namespace when I could
simply do ???namespace::regnamespace?Yes, that is the most important point of this patch.
2. Anticipaed un-optimizability
Tom pointed that these reg* types prevents planner from
optimizing the query, so we should refrain from having such
machinary. It should have been a long-standing issue but reg*s
sees to be rather faster than joining corresponding catalogs
for moderate number of the result rows, but this raises another
more annoying issue.3. Potentially breakage of MVCC
The another issue Tom pointed is potentially breakage of MVCC by
using these reg* types. Syscache is invalidated on updates so
this doesn't seem to be a problem on READ COMMITTED mode, but
breaks SERIALIZABLE mode. But IMHO it is not so serious problem
as long as such inconsistency occurs only on system catalog and
it is explicitly documented togethee with the un-optimizability
issue. I'll add a patch for this later.The way I look at it, all these arguments went out the window when
regclass was introduced.The reality is that reg* is *way* more convenient than manual
joins. The arguments about optimization and MVCC presumably apply to
all reg* casts, which means that ship has long since sailed.I agree basically, but I think some caveat is needed. I'll
include that in the coming documentation patch.If we offered views that made it easier to get at this data then maybe
this wouldn't matter so much. But DBA's don't want to join 3 catalogs
together to try and answer a simple question.It has been annoying me these days.
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Sorry, I sent the previous mail without patches by accident. The
patches are attached to this mail.
====
Hello, this is the patchset v2 of this feature.
0001-Add-regrole.patch
Adding regrole as the name says.
0002-Add-regnamespace.patch
Adding regnamespace. This depends on 0001 patch.
0003-Check-new-reg-types-are-not-used-as-default-values.patch
Inhibiting the new OID aliss types from being used as constants
in default values, which make dependencies on the other
(existing) OID alias types.
0004-Documentation-for-new-OID-alias-types.patch
Documentation patch for this new types.
regards,
At Tue, 17 Feb 2015 20:19:11 +0900 (Tokyo Standard Time), Kyotaro HORIGUCHI <horiguchi.kyotaro@lab.ntt.co.jp> wrote in <20150217.201911.239516619.horiguchi.kyotaro@lab.ntt.co.jp>
Hello, thank you for the comment.
The current patch lacks change in documentation and dependency
stuff. Current framework doesn't consider changing pg_shdepend
from column default expressions so the possible measures are the
followings, I think.1. Make pg_shdepend to have refobjsubid and add some deptypes of
pg_depend, specifically DEPENDENCY_NORMAL is needed. Then,
change the dependency stuff.2. Simplly inhibit specifying them in default
expressions. Integer or OID can act as the replacement.=# create table t1 (a int, b regrole default 'horiguti'::regrole);
ERROR: Type 'regrole' cannot have a default value1 is quite overkill but hardly seems to be usable. So I will go
on 2 and post additional patch.At Thu, 12 Feb 2015 17:12:24 -0600, Jim Nasby <Jim.Nasby@BlueTreble.com> wrote in <54DD3358.9030601@BlueTreble.com>
On 2/12/15 5:28 AM, Kyotaro HORIGUCHI wrote:
Hello, I changed the subject.
# Ouch! the subject remaines wrong..
1. Expected frequency of use
...
For that reason, although the current policy of deciding whether
to have reg* types seems to be whether they have schema-qualified
names, I think regrole and regnamespace are valuable to have.Perhaps schema qualification was the original intent, but I think at
this point everyone uses them for convenience. Why would I want to
type out JOIN pg_namespace n ON n.oid = blah.???namespace when I could
simply do ???namespace::regnamespace?Yes, that is the most important point of this patch.
2. Anticipaed un-optimizability
Tom pointed that these reg* types prevents planner from
optimizing the query, so we should refrain from having such
machinary. It should have been a long-standing issue but reg*s
sees to be rather faster than joining corresponding catalogs
for moderate number of the result rows, but this raises another
more annoying issue.3. Potentially breakage of MVCC
The another issue Tom pointed is potentially breakage of MVCC by
using these reg* types. Syscache is invalidated on updates so
this doesn't seem to be a problem on READ COMMITTED mode, but
breaks SERIALIZABLE mode. But IMHO it is not so serious problem
as long as such inconsistency occurs only on system catalog and
it is explicitly documented togethee with the un-optimizability
issue. I'll add a patch for this later.The way I look at it, all these arguments went out the window when
regclass was introduced.The reality is that reg* is *way* more convenient than manual
joins. The arguments about optimization and MVCC presumably apply to
all reg* casts, which means that ship has long since sailed.I agree basically, but I think some caveat is needed. I'll
include that in the coming documentation patch.If we offered views that made it easier to get at this data then maybe
this wouldn't matter so much. But DBA's don't want to join 3 catalogs
together to try and answer a simple question.It has been annoying me these days.
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
0001-Add-regrole.patchtext/x-patch; charset=us-asciiDownload
>From 2a6f689afdc8197c2fe2fc235a4819ce1a5e9928 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 18 Feb 2015 14:38:32 +0900
Subject: [PATCH 1/4] Add regrole
Add new regtype regrole. For the development reason, the system OIDs
used for the new procs, types, casts are making a gap from existing
OIDs.
---
src/backend/bootstrap/bootstrap.c | 2 +
src/backend/utils/adt/regproc.c | 101 ++++++++++++++++++++++++++++++++++
src/backend/utils/adt/selfuncs.c | 2 +
src/backend/utils/cache/catcache.c | 1 +
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 10 ++++
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 26 ++++++++-
src/test/regress/sql/regproc.sql | 7 +++
10 files changed, 165 insertions(+), 1 deletion(-)
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index bc66eac..11e40ee 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -113,6 +113,8 @@ static const struct typinfo TypInfo[] = {
F_REGPROCIN, F_REGPROCOUT},
{"regtype", REGTYPEOID, 0, 4, true, 'i', 'p', InvalidOid,
F_REGTYPEIN, F_REGTYPEOUT},
+ {"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
+ F_REGROLEIN, F_REGROLEOUT},
{"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 3d1bb32..ec4893f 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -40,6 +40,7 @@
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/tqual.h"
+#include "utils/acl.h"
static char *format_operator_internal(Oid operator_oid, bool force_qualify);
static char *format_procedure_internal(Oid procedure_oid, bool force_qualify);
@@ -1553,6 +1554,106 @@ regdictionarysend(PG_FUNCTION_ARGS)
return oidsend(fcinfo);
}
+/*
+ * regrolein - converts "regrole" to role OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_ts_dict entry.
+ *
+ * This function is not needed in bootstrap mode, so we don't worry about
+ * making it work then.
+ */
+Datum
+regrolein(PG_FUNCTION_ARGS)
+{
+ char *role_or_oid = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ /* '-' ? */
+ if (strcmp(role_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (role_or_oid[0] >= '0' &&
+ role_or_oid[0] <= '9' &&
+ strspn(role_or_oid, "0123456789") == strlen(role_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(role_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /*
+ * Normal case: parse the name into components and see if it matches any
+ * pg_role entries in the current search path.
+ */
+ result = get_role_oid(role_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regrole - converts "role name" to role OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regrole(PG_FUNCTION_ARGS)
+{
+ char *role_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_role_oid(role_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regroleout - converts role OID to "role_name"
+ */
+Datum
+regroleout(PG_FUNCTION_ARGS)
+{
+ Oid roleoid = PG_GETARG_OID(0);
+ char *result;
+
+
+ if (roleoid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = GetUserNameFromId(roleoid);
+ PG_RETURN_CSTRING(result);
+}
+
+/*
+ * regrolerecv - converts external binary format to regrole
+ */
+Datum
+regrolerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regrolesend - converts regrole to binary format
+ */
+Datum
+regrolesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
+
+
/*
* text_regclass: convert text to regclass
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 1ba103c..529b0ed 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3619,6 +3619,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
*scaledvalue = convert_numeric_to_scalar(value, valuetypid);
*scaledlobound = convert_numeric_to_scalar(lobound, boundstypid);
*scaledhibound = convert_numeric_to_scalar(hibound, boundstypid);
@@ -3724,6 +3725,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
/* we can treat OIDs as integers... */
return (double) DatumGetObjectId(value);
}
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 2e4d0b3..51ba43d 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -150,6 +150,7 @@ GetCCHashEqFuncs(Oid keytype, PGFunction *hashfunc, RegProcedure *eqfunc)
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
*hashfunc = hashoid;
*eqfunc = F_OIDEQ;
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index b314369..bc0faa8 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -210,6 +210,13 @@ DATA(insert ( 3769 20 1288 a f ));
DATA(insert ( 3769 23 0 a b ));
DATA(insert ( 25 2205 1079 i f ));
DATA(insert ( 1043 2205 1079 i f ));
+DATA(insert ( 26 4096 0 i b ));
+DATA(insert ( 4096 26 0 i b ));
+DATA(insert ( 20 4096 1287 i f ));
+DATA(insert ( 21 4096 313 i f ));
+DATA(insert ( 23 4096 0 i b ));
+DATA(insert ( 4096 20 1288 a f ));
+DATA(insert ( 4096 23 0 a b ));
/*
* String category
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 9edfdb8..b2b4beb 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3436,6 +3436,12 @@ DESCR("convert type name to regtype");
DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "25" _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ ));
DESCR("convert text to regclass");
+DATA(insert OID = 4091 ( regrolein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ regrolein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4096" _null_ _null_ _null_ _null_ regroleout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
+DESCR("convert role name to regrole");
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
DESCR("(internal)");
DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
@@ -3831,6 +3837,10 @@ DATA(insert OID = 2454 ( regtyperecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1
DESCR("I/O");
DATA(insert OID = 2455 ( regtypesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2206" _null_ _null_ _null_ _null_ regtypesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4096 "2281" _null_ _null_ _null_ _null_ regrolerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 0a900dd..1430bc1 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -564,12 +564,17 @@ DATA(insert OID = 2206 ( regtype PGNSP PGUID 4 t b N f t \054 0 0 2211 regty
DESCR("registered type");
#define REGTYPEOID 2206
+DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 regrolein regroleout regrolerecv regrolesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered role");
+#define REGROLEOID 4096
+
DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
+DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index bc4517d..0e1e99e 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -630,6 +630,11 @@ extern Datum regtypeout(PG_FUNCTION_ARGS);
extern Datum regtyperecv(PG_FUNCTION_ARGS);
extern Datum regtypesend(PG_FUNCTION_ARGS);
extern Datum to_regtype(PG_FUNCTION_ARGS);
+extern Datum regrolein(PG_FUNCTION_ARGS);
+extern Datum regroleout(PG_FUNCTION_ARGS);
+extern Datum regrolerecv(PG_FUNCTION_ARGS);
+extern Datum regrolesend(PG_FUNCTION_ARGS);
+extern Datum to_regrole(PG_FUNCTION_ARGS);
extern Datum regconfigin(PG_FUNCTION_ARGS);
extern Datum regconfigout(PG_FUNCTION_ARGS);
extern Datum regconfigrecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index 3342129..beda8ec 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -2,6 +2,7 @@
-- regproc
--
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
regoper
@@ -39,6 +40,12 @@ SELECT regtype('int4');
integer
(1 row)
+SELECT regrole('regtestrole');
+ regrole
+-------------
+ regtestrole
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -75,6 +82,12 @@ SELECT to_regtype('int4');
integer
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+-------------
+ regtestrole
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -143,10 +156,11 @@ SELECT to_regtype('pg_catalog.int4');
(1 row)
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
-- without schemaname
SELECT regoper('||//');
ERROR: operator does not exist: ||//
-LINE 3: SELECT regoper('||//');
+LINE 1: SELECT regoper('||//');
^
SELECT regoperator('++(int4,int4)');
ERROR: operator does not exist: ++(int4,int4)
@@ -168,6 +182,10 @@ SELECT regtype('int3');
ERROR: type "int3" does not exist
LINE 1: SELECT regtype('int3');
^
+SELECT regrole('regtestrole');
+ERROR: role "regtestrole" does not exist
+LINE 1: SELECT regrole('regtestrole');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -231,6 +249,12 @@ SELECT to_regtype('int3');
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index cc90838..bc77c67 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -4,6 +4,7 @@
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
@@ -12,6 +13,7 @@ SELECT regproc('now');
SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
+SELECT regrole('regtestrole');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -19,6 +21,7 @@ SELECT to_regproc('now');
SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
+SELECT to_regrole('regtestrole');
-- with schemaname
@@ -37,6 +40,8 @@ SELECT to_regtype('pg_catalog.int4');
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
+
-- without schemaname
SELECT regoper('||//');
@@ -45,6 +50,7 @@ SELECT regproc('know');
SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
+SELECT regrole('regtestrole');
-- with schemaname
@@ -65,6 +71,7 @@ SELECT to_regproc('know');
SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
+SELECT to_regrole('regtestrole');
-- with schemaname
--
2.1.0.GIT
0002-Add-regnamespace.patchtext/x-patch; charset=us-asciiDownload
>From 565565b5818575d1540dabf8c2f9e580f266d1a2 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 18 Feb 2015 15:14:27 +0900
Subject: [PATCH 2/4] Add regnamespace.
Add new regtype regnamespace.
---
src/backend/bootstrap/bootstrap.c | 2 +
src/backend/utils/adt/regproc.c | 97 +++++++++++++++++++++++++++++++++++
src/backend/utils/adt/selfuncs.c | 2 +
src/backend/utils/cache/catcache.c | 1 +
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 10 ++++
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 22 ++++++++
src/test/regress/sql/regproc.sql | 4 ++
10 files changed, 155 insertions(+)
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index 11e40ee..c38e1fc 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -113,6 +113,8 @@ static const struct typinfo TypInfo[] = {
F_REGPROCIN, F_REGPROCOUT},
{"regtype", REGTYPEOID, 0, 4, true, 'i', 'p', InvalidOid,
F_REGTYPEIN, F_REGTYPEOUT},
+ {"regnamespace", REGNAMESPACEOID, 0, 4, true, 'i', 'p', InvalidOid,
+ F_REGNAMESPACEIN, F_REGNAMESPACEOUT},
{"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
F_REGROLEIN, F_REGROLEOUT},
{"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index ec4893f..6155e4f 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -1160,6 +1160,103 @@ regclasssend(PG_FUNCTION_ARGS)
/*
+ * regnamespacein - converts "classname" to class OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_class entry.
+ */
+Datum
+regnamespacein(PG_FUNCTION_ARGS)
+{
+ char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
+ Oid result = InvalidOid;
+
+ /* '-' ? */
+ if (strcmp(nsp_name_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (nsp_name_or_oid[0] >= '0' &&
+ nsp_name_or_oid[0] <= '9' &&
+ strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(nsp_name_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /* Else it's a name */
+
+ result = get_namespace_oid(nsp_name_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regnamespace - converts "nspname" to namespace OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regnamespace(PG_FUNCTION_ARGS)
+{
+ char *nsp_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_namespace_oid(nsp_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regnamespaceout - converts namespace OID to "nspname"
+ */
+Datum
+regnamespaceout(PG_FUNCTION_ARGS)
+{
+ Oid nspid = PG_GETARG_OID(0);
+ char *result;
+
+ if (nspid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = get_namespace_name(nspid);
+ if (result)
+ PG_RETURN_CSTRING(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regnamespacerecv - converts external binary format to regnamespace
+ */
+Datum
+regnamespacerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regnamespacesend - converts regnamespace to binary format
+ */
+Datum
+regnamespacesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
+
+
+/*
* regtypein - converts "typename" to type OID
*
* We also accept a numeric OID, for symmetry with the output routine.
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 529b0ed..1761729 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3620,6 +3620,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
*scaledvalue = convert_numeric_to_scalar(value, valuetypid);
*scaledlobound = convert_numeric_to_scalar(lobound, boundstypid);
*scaledhibound = convert_numeric_to_scalar(hibound, boundstypid);
@@ -3726,6 +3727,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
/* we can treat OIDs as integers... */
return (double) DatumGetObjectId(value);
}
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 51ba43d..3bce4de 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -151,6 +151,7 @@ GetCCHashEqFuncs(Oid keytype, PGFunction *hashfunc, RegProcedure *eqfunc)
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
*hashfunc = hashoid;
*eqfunc = F_OIDEQ;
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index bc0faa8..fad168f 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -210,6 +210,13 @@ DATA(insert ( 3769 20 1288 a f ));
DATA(insert ( 3769 23 0 a b ));
DATA(insert ( 25 2205 1079 i f ));
DATA(insert ( 1043 2205 1079 i f ));
+DATA(insert ( 26 4089 0 i b ));
+DATA(insert ( 4089 26 0 i b ));
+DATA(insert ( 20 4089 1287 i f ));
+DATA(insert ( 21 4089 313 i f ));
+DATA(insert ( 23 4089 0 i b ));
+DATA(insert ( 4089 20 1288 a f ));
+DATA(insert ( 4089 23 0 a b ));
DATA(insert ( 26 4096 0 i b ));
DATA(insert ( 4096 26 0 i b ));
DATA(insert ( 20 4096 1287 i f ));
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index b2b4beb..a292394 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3436,6 +3436,12 @@ DESCR("convert type name to regtype");
DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "25" _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ ));
DESCR("convert text to regclass");
+DATA(insert OID = 4084 ( regnamespacein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ regnamespacein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4085 ( regnamespaceout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4089" _null_ _null_ _null_ _null_ regnamespaceout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4086 ( to_regnamespace PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ to_regnamespace _null_ _null_ _null_ ));
+DESCR("convert namespace name to regnamespace");
DATA(insert OID = 4091 ( regrolein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ regrolein _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4096" _null_ _null_ _null_ _null_ regroleout _null_ _null_ _null_ ));
@@ -3837,6 +3843,10 @@ DATA(insert OID = 2454 ( regtyperecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1
DESCR("I/O");
DATA(insert OID = 2455 ( regtypesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2206" _null_ _null_ _null_ _null_ regtypesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4087 ( regnamespacerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4089 "2281" _null_ _null_ _null_ _null_ regnamespacerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4088 ( regnamespacesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4089" _null_ _null_ _null_ _null_ regnamespacesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4096 "2281" _null_ _null_ _null_ _null_ regrolerecv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 1430bc1..0bd3fbd 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -564,6 +564,10 @@ DATA(insert OID = 2206 ( regtype PGNSP PGUID 4 t b N f t \054 0 0 2211 regty
DESCR("registered type");
#define REGTYPEOID 2206
+DATA(insert OID = 4089 ( regnamespace PGNSP PGUID 4 t b N f t \054 0 0 4090 regnamespacein regnamespaceout regnamespacerecv regnamespacesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered namespace");
+#define REGNAMESPACEOID 4089
+
DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 regrolein regroleout regrolerecv regrolesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
DESCR("registered role");
#define REGROLEOID 4096
@@ -574,6 +578,7 @@ DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 ar
DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
+DATA(insert OID = 4090 ( _regnamespace PGNSP PGUID -1 f b A f t \054 0 4089 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 0e1e99e..a95ed23 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -630,6 +630,11 @@ extern Datum regtypeout(PG_FUNCTION_ARGS);
extern Datum regtyperecv(PG_FUNCTION_ARGS);
extern Datum regtypesend(PG_FUNCTION_ARGS);
extern Datum to_regtype(PG_FUNCTION_ARGS);
+extern Datum regnamespacein(PG_FUNCTION_ARGS);
+extern Datum regnamespaceout(PG_FUNCTION_ARGS);
+extern Datum regnamespacerecv(PG_FUNCTION_ARGS);
+extern Datum regnamespacesend(PG_FUNCTION_ARGS);
+extern Datum to_regnamespace(PG_FUNCTION_ARGS);
extern Datum regrolein(PG_FUNCTION_ARGS);
extern Datum regroleout(PG_FUNCTION_ARGS);
extern Datum regrolerecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index beda8ec..8c734f4 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -46,6 +46,12 @@ SELECT regrole('regtestrole');
regtestrole
(1 row)
+SELECT regnamespace('pg_catalog');
+ regnamespace
+--------------
+ pg_catalog
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -88,6 +94,12 @@ SELECT to_regrole('regtestrole');
regtestrole
(1 row)
+SELECT to_regnamespace('pg_catalog');
+ to_regnamespace
+-----------------
+ pg_catalog
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -186,6 +198,10 @@ SELECT regrole('regtestrole');
ERROR: role "regtestrole" does not exist
LINE 1: SELECT regrole('regtestrole');
^
+SELECT regnamespace('nonexistent');
+ERROR: schema "nonexistent" does not exist
+LINE 1: SELECT regnamespace('nonexistent');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -255,6 +271,12 @@ SELECT to_regrole('regtestrole');
(1 row)
+SELECT to_regnamespace('nonexistent');
+ to_regnamespace
+-----------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index bc77c67..8edaf15 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -14,6 +14,7 @@ SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
SELECT regrole('regtestrole');
+SELECT regnamespace('pg_catalog');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -22,6 +23,7 @@ SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
SELECT to_regrole('regtestrole');
+SELECT to_regnamespace('pg_catalog');
-- with schemaname
@@ -51,6 +53,7 @@ SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
SELECT regrole('regtestrole');
+SELECT regnamespace('nonexistent');
-- with schemaname
@@ -72,6 +75,7 @@ SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
SELECT to_regrole('regtestrole');
+SELECT to_regnamespace('nonexistent');
-- with schemaname
--
2.1.0.GIT
0003-Check-new-reg-types-are-not-used-as-default-values.patchtext/x-patch; charset=us-asciiDownload
>From 648f702b90ae05564e2792277ce279047f53566c Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Mon, 16 Feb 2015 20:05:43 +0900
Subject: [PATCH 3/4] Check new reg* types are not used as default values
The new OID alias types don't behave as the same as the other OID
alias types concerning object dependency. To get rid of confusion,
inhibit constants of these types from appearing where dependencies are
registered for other types.
---
src/backend/catalog/dependency.c | 23 +++++++++++++++++++++++
src/backend/catalog/heap.c | 1 +
2 files changed, 24 insertions(+)
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index bacb242..a59c2cd 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1597,6 +1597,29 @@ find_expr_references_walker(Node *node,
add_object_address(OCLASS_TSDICT, objoid, 0,
context->addrs);
break;
+
+ /*
+ * Dependencies for regrole and regnamespace in expressions
+ * are not handled as same as other reg* types. So explicitly
+ * inhibit the usage to get rid of confusions.
+ */
+ case REGROLEOID:
+ case REGNAMESPACEOID:
+ {
+ HeapTuple tt;
+ char *typename = "<unknown>";
+
+ tt = SearchSysCache1(TYPEOID, con->consttype);
+ if (HeapTupleIsValid(tt))
+ typename = pstrdup(NameStr(((Form_pg_type)
+ GETSTRUCT(tt))->typname));
+ ReleaseSysCache(tt);
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("constant of the type \'%s\' cannot be used here",
+ typename)));
+ }
+ break;
}
}
return false;
diff --git a/src/backend/catalog/heap.c b/src/backend/catalog/heap.c
index 17f7266..fa5957a 100644
--- a/src/backend/catalog/heap.c
+++ b/src/backend/catalog/heap.c
@@ -1860,6 +1860,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
Oid attrdefOid;
ObjectAddress colobject,
defobject;
+ Oid exprtype;
/*
* Flatten expression to string form for storage.
--
2.1.0.GIT
0004-Documentation-for-new-OID-alias-types.patchtext/x-patch; charset=us-asciiDownload
>From c5a9ca98342dd032996b1c138cf414bf1b64f460 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 18 Feb 2015 15:42:54 +0900
Subject: [PATCH 4/4] Documentation for new OID alias types.
Added description about regrole and regnamespace and modified some
existing descriptions according to the restriction of these new
types. Addition to it, put a note about MVCC violation and
optimization issues.
---
doc/src/sgml/datatype.sgml | 54 ++++++++++++++++++++++++++++++++++------------
1 file changed, 40 insertions(+), 14 deletions(-)
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index edf636b..78a70ee 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4319,7 +4319,8 @@ SET xmloption TO { DOCUMENT | CONTENT };
an object identifier. There are also several alias types for
<type>oid</>: <type>regproc</>, <type>regprocedure</>,
<type>regoper</>, <type>regoperator</>, <type>regclass</>,
- <type>regtype</>, <type>regconfig</>, and <type>regdictionary</>.
+ <type>regtype</>, <type>regrole</>, <type>regnamespace</>,
+ <type>regconfig</>, and <type>regdictionary</>.
<xref linkend="datatype-oid-table"> shows an overview.
</para>
@@ -4429,6 +4430,20 @@ SELECT * FROM pg_attribute
</row>
<row>
+ <entry><type>regrole</></entry>
+ <entry><structname>pg_authid</></entry>
+ <entry>role name</entry>
+ <entry><literal>John</></entry>
+ </row>
+
+ <row>
+ <entry><type>regnamespace</></entry>
+ <entry><structname>pg_namespace</></entry>
+ <entry>namespace name</entry>
+ <entry><literal>pg_catalog</></entry>
+ </row>
+
+ <row>
<entry><type>regconfig</></entry>
<entry><structname>pg_ts_config</></entry>
<entry>text search configuration</entry>
@@ -4446,30 +4461,41 @@ SELECT * FROM pg_attribute
</table>
<para>
- All of the OID alias types accept schema-qualified names, and will
- display schema-qualified names on output if the object would not
- be found in the current search path without being qualified.
- The <type>regproc</> and <type>regoper</> alias types will only
- accept input names that are unique (not overloaded), so they are
- of limited use; for most uses <type>regprocedure</> or
+ All of the OID alias types for objects grouped by namespace accept
+ schema-qualified names, and will display schema-qualified names on output
+ if the object would not be found in the current search path without being
+ qualified. The <type>regproc</> and <type>regoper</> alias types will
+ only accept input names that are unique (not overloaded), so they are of
+ limited use; for most uses <type>regprocedure</> or
<type>regoperator</> are more appropriate. For <type>regoperator</>,
unary operators are identified by writing <literal>NONE</> for the unused
operand.
</para>
<para>
- An additional property of the OID alias types is the creation of
- dependencies. If a
- constant of one of these types appears in a stored expression
- (such as a column default expression or view), it creates a dependency
- on the referenced object. For example, if a column has a default
- expression <literal>nextval('my_seq'::regclass)</>,
+ An additional property of most of the OID alias types is the creation of
+ dependencies. If a constant of one of these types appears in a stored
+ expression (such as a column default expression or view), it creates a
+ dependency on the referenced object. For example, if a column has a
+ default expression <literal>nextval('my_seq'::regclass)</>,
<productname>PostgreSQL</productname>
understands that the default expression depends on the sequence
<literal>my_seq</>; the system will not let the sequence be dropped
- without first removing the default expression.
+ without first removing the default expression. <type>regrole</>
+ and <type>regnamespace</> are the exceptions for the property. Constants
+ of these types are not allowed in such expressions.
</para>
+ <note>
+ <para>
+ The OID alias types don't sctrictly comply the transaction isolation
+ rules so do not use them where exact transaction isolation on the values
+ of theses types has a significance. Likewise, since they look as simple
+ constants to planner so you might get slower plans than the queries
+ joining the system tables correnspond to the OID types.
+ </para>
+ </note>
+
<para>
Another identifier type used by the system is <type>xid</>, or transaction
(abbreviated <abbrev>xact</>) identifier. This is the data type of the system columns
--
2.1.0.GIT
On 2/18/15 3:44 AM, Kyotaro HORIGUCHI wrote:
Sorry, I sent the previous mail without patches by accident. The
patches are attached to this mail.====
Hello, this is the patchset v2 of this feature.0001-Add-regrole.patch
Adding regrole as the name says.0002-Add-regnamespace.patch
Adding regnamespace. This depends on 0001 patch.0003-Check-new-reg-types-are-not-used-as-default-values.patch
Inhibiting the new OID aliss types from being used as constants
in default values, which make dependencies on the other
(existing) OID alias types.0004-Documentation-for-new-OID-alias-types.patch
Documentation patch for this new types.
Somehow, these patches ended up in the commit fest without an author
listed. That should probably not be possible.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello,
At Thu, 19 Feb 2015 15:30:53 -0500, Peter Eisentraut <peter_e@gmx.net> wrote in <54E647FD.5000208@gmx.net>
On 2/18/15 3:44 AM, Kyotaro HORIGUCHI wrote:
Hello, this is the patchset v2 of this feature.
0001-Add-regrole.patch
0002-Add-regnamespace.patch
0003-Check-new-reg-types-are-not-used-as-default-values.patch
0004-Documentation-for-new-OID-alias-types.patchSomehow, these patches ended up in the commit fest without an author
listed. That should probably not be possible.
Mmm.. I saw the author for this is listed here,
https://commitfest.postgresql.org/4/
Did you fix that manually for me?
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On Tue, Feb 24, 2015 at 11:35 AM, Kyotaro HORIGUCHI <
horiguchi.kyotaro@lab.ntt.co.jp> wrote:
Hello,
At Thu, 19 Feb 2015 15:30:53 -0500, Peter Eisentraut <peter_e@gmx.net>
wrote in <54E647FD.5000208@gmx.net>On 2/18/15 3:44 AM, Kyotaro HORIGUCHI wrote:
Hello, this is the patchset v2 of this feature.
0001-Add-regrole.patch
0002-Add-regnamespace.patch
0003-Check-new-reg-types-are-not-used-as-default-values.patch
0004-Documentation-for-new-OID-alias-types.patchSomehow, these patches ended up in the commit fest without an author
listed. That should probably not be possible.Mmm.. I saw the author for this is listed here,
https://commitfest.postgresql.org/4/
Did you fix that manually for me?
Looking at the log entry:
2015-02-19 21:11:08 Michael Paquier (michael-kun) Changed authors to
Kyotaro Horiguchi (horiguti)
I do a pass from time to on the patches...
--
Michael
At Tue, 24 Feb 2015 14:11:28 +0900, Michael Paquier <michael.paquier@gmail.com> wrote in <CAB7nPqT6Ox3MV++hgmbd3YDU_5-1y5HCDDmsTK+QDYA_MjpFVg@mail.gmail.com>
https://commitfest.postgresql.org/4/
Did you fix that manually for me?
Looking at the log entry:
2015-02-19 21:11:08 Michael Paquier (michael-kun) Changed authors to
Kyotaro Horiguchi (horiguti)
I do a pass from time to on the patches...
Ah, I found it. Thank you.
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hi,
Personally, I was looking for something like this as I need to see rolename
and namespace name many times in my queries rather than it's oid.
But making a JOIN expression every-time was a pain. This certainly makes it
easier. And I see most DBAs are looking for it.
I agree on Tom's concern on MVCC issue, but we already hit that when we
introduced regclass and others. So I see no additional issue with these
changes as such. About planner slowness, I guess updated documentation looks
perfect for that.
So I went ahead reviewing these patches.
All patches are straight forward and since we have similar code already
exists, I did not find any issue at code level. They are consistent with
other
functions.
Patches applies with patch -p1. make, make install, make check has
no issues. Testing was fine too.
However here are few review comments on the patches attached:
Review points on 0001-Add-regrole.patch
---
1.
+#include "utils/acl.h"
Can you please add it at appropriate place as #include list is an ordered
list
2.
+ char *role_or_oid = PG_GETARG_CSTRING(0);
Can we have variable named as role_name_or_oid, like other similar
functions?
3.
+ /*
+ * Normal case: parse the name into components and see if it matches
any
+ * pg_role entries in the current search path.
+ */
I believe, roles are never searched per search path. Thus need to update
comments here.
Review points on 0002-Add-regnamespace.patch
---
1.
+ * regnamespacein - converts "classname" to class OID
Typos. Should be nspname instead of classname and namespase OID instead of
class OID
Review points on 0003-Check-new....patch
---
1.
@@ -1860,6 +1860,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
Oid attrdefOid;
ObjectAddress colobject,
defobject;
+ Oid exprtype;
This seems unrelated. Please remove.
Apart from this, it will be good if you have ONLY two patches,
(1) For regrole and (2) For regnamespace specific
With all related changes into one patch. I mean, all role related changes
i.e.
0001 + 0003 role related changes + 0004 role related changes and docs update
AND
0002 + 0003 nsp related changes + 0004 nsp related changes
Thanks
--
Jeevan B Chalke
Principal Software Engineer, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
Reviewed posted directly on mail thread instead of posting it on commitfest app.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello, thank you for reviewing.
The attatched are the third version of this patch.
0001-Add-regrole_v3.patch
0002-Add-regnamespace_v3.patch
- Rearranged into regrole patch and regnamespace patch as seen
above, each of them consists of changes for code, docs,
regtests. regnamespace patch depends on the another patch.
- Removed the irrelevant change and corrected mistakes in
comments.
- Renamed role_or_oid to role_name_or_oid in regrolein().
- Changed the example name for regrole in the docmentation to
'smithee' as an impossible-in-reality-but-well-known name, from
'john', the most common in US (according to Wikipedia).
At Tue, 24 Feb 2015 16:30:44 +0530, Jeevan Chalke <jeevan.chalke@enterprisedb.com> wrote in <CAM2+6=V-fwQFkwF0Pi3Dacq-ZRY5WxcPLVLuqFKf2Mf57_6inA@mail.gmail.com>
I agree on Tom's concern on MVCC issue, but we already hit that when we
introduced regclass and others. So I see no additional issue with these
changes as such. About planner slowness, I guess updated documentation looks
perfect for that.So I went ahead reviewing these patches.
All patches are straight forward and since we have similar code already
exists, I did not find any issue at code level. They are consistent with
other
functions.
One concern is about arbitrary allocation of OIDs for the new
objects - types, functions. They are isolated from other similar
reg* types, but there's no help for it without global renumbering
of static(system) OIDs.
Patches applies with patch -p1. make, make install, make check has
no issues. Testing was fine too.However here are few review comments on the patches attached:
Review points on 0001-Add-regrole.patch
---
1.
+#include "utils/acl.h"Can you please add it at appropriate place as #include list is an ordered
list
regrolein calls reg_role_oid in acl.c, which is declared in acl.h.
2.
+ char *role_or_oid = PG_GETARG_CSTRING(0);Can we have variable named as role_name_or_oid, like other similar
functions?
I might somehow have thought it a bit long. Fixed.
3. + /* + * Normal case: parse the name into components and see if it matches any + * pg_role entries in the current search path. + */I believe, roles are never searched per search path. Thus need to update
comments here.
Ouch. I forgot to edit it properly. I edit it. The correct
catalog name is pg_authid.
+ /* Normal case: see if the name matches any pg_authid entry. */
I also edited comments for regnamespacein.
Review points on 0002-Add-regnamespace.patch --- 1. + * regnamespacein - converts "classname" to class OIDTypos. Should be nspname instead of classname and namespase OID instead of
class OID
Thank you for pointing out. I fixed the same mistake in
regrolein, p_ts_dict was there instead of pg_authid.. The names
of oid kinds appear in multiple forms, that is, oprname and
opr_name. Although I don't understand the reason, I followed the
convention.
Review points on 0003-Check-new....patch
---
1.
@@ -1860,6 +1860,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
Oid attrdefOid;
ObjectAddress colobject,
defobject;
+ Oid exprtype;This seems unrelated. Please remove.
It's a trace of the previous code to ruling out the new oid
types. Removed.
Apart from this, it will be good if you have ONLY two patches,
(1) For regrole and (2) For regnamespace specific
With all related changes into one patch. I mean, all role related changes
i.e.
0001 + 0003 role related changes + 0004 role related changes and docs update
AND
0002 + 0003 nsp related changes + 0004 nsp related changes
I prudently separated it since I wasn't confident on the
pertinence of ruling out. I rearranged them as your advise
including docs.
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
0001-Add-regrole_v3.patchtext/x-patch; charset=us-asciiDownload
>From 4d56a68e2bf2b7ee0da0447ad9f82f0b46277133 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 18 Feb 2015 14:38:32 +0900
Subject: [PATCH 1/2] Add regrole
Add new OID aliass type regrole. The new type has the scope of whole
the database cluster so it doesn't behave as the same as the existing
OID alias types which have database scope, concerning object
dependency. To get rid of confusion, inhibit constants of the new type
from appearing where dependencies are made involving it.
Documentation about this new type is added and some existing
descriptions are modified according to the restriction of the
type. Addition to it, put a note about possible MVCC violation and
optimization issues, which are general over the all reg* types.
---
doc/src/sgml/datatype.sgml | 55 +++++++++++++-------
src/backend/bootstrap/bootstrap.c | 2 +
src/backend/catalog/dependency.c | 22 ++++++++
src/backend/utils/adt/regproc.c | 98 +++++++++++++++++++++++++++++++++++
src/backend/utils/adt/selfuncs.c | 2 +
src/backend/utils/cache/catcache.c | 1 +
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 10 ++++
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 26 +++++++++-
src/test/regress/sql/regproc.sql | 7 +++
12 files changed, 221 insertions(+), 19 deletions(-)
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index edf636b..095d624 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4319,8 +4319,9 @@ SET xmloption TO { DOCUMENT | CONTENT };
an object identifier. There are also several alias types for
<type>oid</>: <type>regproc</>, <type>regprocedure</>,
<type>regoper</>, <type>regoperator</>, <type>regclass</>,
- <type>regtype</>, <type>regconfig</>, and <type>regdictionary</>.
- <xref linkend="datatype-oid-table"> shows an overview.
+ <type>regtype</>, <type>regrole</>, <type>regconfig</>, and
+ <type>regdictionary</>. <xref linkend="datatype-oid-table"> shows
+ an overview.
</para>
<para>
@@ -4429,6 +4430,13 @@ SELECT * FROM pg_attribute
</row>
<row>
+ <entry><type>regrole</></entry>
+ <entry><structname>pg_authid</></entry>
+ <entry>role name</entry>
+ <entry><literal>smithee</></entry>
+ </row>
+
+ <row>
<entry><type>regconfig</></entry>
<entry><structname>pg_ts_config</></entry>
<entry>text search configuration</entry>
@@ -4446,29 +4454,40 @@ SELECT * FROM pg_attribute
</table>
<para>
- All of the OID alias types accept schema-qualified names, and will
- display schema-qualified names on output if the object would not
- be found in the current search path without being qualified.
- The <type>regproc</> and <type>regoper</> alias types will only
- accept input names that are unique (not overloaded), so they are
- of limited use; for most uses <type>regprocedure</> or
+ All of the OID alias types for objects grouped by namespace accept
+ schema-qualified names, and will display schema-qualified names on output
+ if the object would not be found in the current search path without being
+ qualified. The <type>regproc</> and <type>regoper</> alias types will
+ only accept input names that are unique (not overloaded), so they are of
+ limited use; for most uses <type>regprocedure</> or
<type>regoperator</> are more appropriate. For <type>regoperator</>,
unary operators are identified by writing <literal>NONE</> for the unused
operand.
</para>
<para>
- An additional property of the OID alias types is the creation of
- dependencies. If a
- constant of one of these types appears in a stored expression
- (such as a column default expression or view), it creates a dependency
- on the referenced object. For example, if a column has a default
- expression <literal>nextval('my_seq'::regclass)</>,
- <productname>PostgreSQL</productname>
- understands that the default expression depends on the sequence
- <literal>my_seq</>; the system will not let the sequence be dropped
- without first removing the default expression.
+ An additional property of most of the OID alias types is the creation of
+ dependencies. If a constant of one of these types appears in a stored
+ expression (such as a column default expression or view), it creates a
+ dependency on the referenced object. For example, if a column has
+ a default expression <literal>nextval('my_seq'::regclass)</>,
+ <productname>PostgreSQL</productname> understands that the default
+ expression depends on the sequence <literal>my_seq</>; the system
+ will not let the sequence be dropped without first removing the
+ default expression. <type>regrole</> is the exception for the
+ property. Constants of this type are not allowed in such
+ expressions.
+ </para>
+
+ <note>
+ <para>
+ The OID alias types don't sctrictly comply the transaction isolation
+ rules so do not use them where exact transaction isolation on the values
+ of theses types has a significance. Likewise, since they look as simple
+ constants to planner so you might get slower plans than the queries
+ joining the system tables correnspond to the OID types.
</para>
+ </note>
<para>
Another identifier type used by the system is <type>xid</>, or transaction
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index ad49964..c375c96 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -113,6 +113,8 @@ static const struct typinfo TypInfo[] = {
F_REGPROCIN, F_REGPROCOUT},
{"regtype", REGTYPEOID, 0, 4, true, 'i', 'p', InvalidOid,
F_REGTYPEIN, F_REGTYPEOUT},
+ {"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
+ F_REGROLEIN, F_REGROLEOUT},
{"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index bacb242..c85f70a 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1597,6 +1597,28 @@ find_expr_references_walker(Node *node,
add_object_address(OCLASS_TSDICT, objoid, 0,
context->addrs);
break;
+
+ /*
+ * Dependencies for regrole in expressions are not handled as
+ * same as other reg* types. So explicitly inhibit the usage
+ * to get rid of confusions.
+ */
+ case REGROLEOID:
+ {
+ HeapTuple tt;
+ char *typename = "<unknown>";
+
+ tt = SearchSysCache1(TYPEOID, con->consttype);
+ if (HeapTupleIsValid(tt))
+ typename = pstrdup(NameStr(((Form_pg_type)
+ GETSTRUCT(tt))->typname));
+ ReleaseSysCache(tt);
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("constant of the type \'%s\' cannot be used here",
+ typename)));
+ }
+ break;
}
}
return false;
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 3d1bb32..a5196e7 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -40,6 +40,7 @@
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/tqual.h"
+#include "utils/acl.h"
static char *format_operator_internal(Oid operator_oid, bool force_qualify);
static char *format_procedure_internal(Oid procedure_oid, bool force_qualify);
@@ -1553,6 +1554,103 @@ regdictionarysend(PG_FUNCTION_ARGS)
return oidsend(fcinfo);
}
+/*
+ * regrolein - converts "rolename" to role OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_authid entry.
+ *
+ * This function is not needed in bootstrap mode, so we don't worry about
+ * making it work then.
+ */
+Datum
+regrolein(PG_FUNCTION_ARGS)
+{
+ char *role_name_or_oid = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ /* '-' ? */
+ if (strcmp(role_name_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (role_name_or_oid[0] >= '0' &&
+ role_name_or_oid[0] <= '9' &&
+ strspn(role_name_or_oid, "0123456789") == strlen(role_name_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(role_name_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /* Normal case: see if the name matches any pg_authid entry. */
+ result = get_role_oid(role_name_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regrole - converts "rolename" to role OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regrole(PG_FUNCTION_ARGS)
+{
+ char *role_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_role_oid(role_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regroleout - converts role OID to "role_name"
+ */
+Datum
+regroleout(PG_FUNCTION_ARGS)
+{
+ Oid roleoid = PG_GETARG_OID(0);
+ char *result;
+
+
+ if (roleoid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = GetUserNameFromId(roleoid);
+ PG_RETURN_CSTRING(result);
+}
+
+/*
+ * regrolerecv - converts external binary format to regrole
+ */
+Datum
+regrolerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regrolesend - converts regrole to binary format
+ */
+Datum
+regrolesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
+
+
/*
* text_regclass: convert text to regclass
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 1ba103c..529b0ed 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3619,6 +3619,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
*scaledvalue = convert_numeric_to_scalar(value, valuetypid);
*scaledlobound = convert_numeric_to_scalar(lobound, boundstypid);
*scaledhibound = convert_numeric_to_scalar(hibound, boundstypid);
@@ -3724,6 +3725,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
/* we can treat OIDs as integers... */
return (double) DatumGetObjectId(value);
}
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 1af43c6..9b7cc5e 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -150,6 +150,7 @@ GetCCHashEqFuncs(Oid keytype, PGFunction *hashfunc, RegProcedure *eqfunc)
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
*hashfunc = hashoid;
*eqfunc = F_OIDEQ;
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index b314369..bc0faa8 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -210,6 +210,13 @@ DATA(insert ( 3769 20 1288 a f ));
DATA(insert ( 3769 23 0 a b ));
DATA(insert ( 25 2205 1079 i f ));
DATA(insert ( 1043 2205 1079 i f ));
+DATA(insert ( 26 4096 0 i b ));
+DATA(insert ( 4096 26 0 i b ));
+DATA(insert ( 20 4096 1287 i f ));
+DATA(insert ( 21 4096 313 i f ));
+DATA(insert ( 23 4096 0 i b ));
+DATA(insert ( 4096 20 1288 a f ));
+DATA(insert ( 4096 23 0 a b ));
/*
* String category
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 4268b99..2aa7c33 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3438,6 +3438,12 @@ DESCR("convert type name to regtype");
DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "25" _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ ));
DESCR("convert text to regclass");
+DATA(insert OID = 4091 ( regrolein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ regrolein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4096" _null_ _null_ _null_ _null_ regroleout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
+DESCR("convert role name to regrole");
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
DESCR("(internal)");
DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
@@ -3833,6 +3839,10 @@ DATA(insert OID = 2454 ( regtyperecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1
DESCR("I/O");
DATA(insert OID = 2455 ( regtypesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2206" _null_ _null_ _null_ _null_ regtypesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4096 "2281" _null_ _null_ _null_ _null_ regrolerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 0a900dd..1430bc1 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -564,12 +564,17 @@ DATA(insert OID = 2206 ( regtype PGNSP PGUID 4 t b N f t \054 0 0 2211 regty
DESCR("registered type");
#define REGTYPEOID 2206
+DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 regrolein regroleout regrolerecv regrolesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered role");
+#define REGROLEOID 4096
+
DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
+DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index bc4517d..0e1e99e 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -630,6 +630,11 @@ extern Datum regtypeout(PG_FUNCTION_ARGS);
extern Datum regtyperecv(PG_FUNCTION_ARGS);
extern Datum regtypesend(PG_FUNCTION_ARGS);
extern Datum to_regtype(PG_FUNCTION_ARGS);
+extern Datum regrolein(PG_FUNCTION_ARGS);
+extern Datum regroleout(PG_FUNCTION_ARGS);
+extern Datum regrolerecv(PG_FUNCTION_ARGS);
+extern Datum regrolesend(PG_FUNCTION_ARGS);
+extern Datum to_regrole(PG_FUNCTION_ARGS);
extern Datum regconfigin(PG_FUNCTION_ARGS);
extern Datum regconfigout(PG_FUNCTION_ARGS);
extern Datum regconfigrecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index 3342129..beda8ec 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -2,6 +2,7 @@
-- regproc
--
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
regoper
@@ -39,6 +40,12 @@ SELECT regtype('int4');
integer
(1 row)
+SELECT regrole('regtestrole');
+ regrole
+-------------
+ regtestrole
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -75,6 +82,12 @@ SELECT to_regtype('int4');
integer
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+-------------
+ regtestrole
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -143,10 +156,11 @@ SELECT to_regtype('pg_catalog.int4');
(1 row)
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
-- without schemaname
SELECT regoper('||//');
ERROR: operator does not exist: ||//
-LINE 3: SELECT regoper('||//');
+LINE 1: SELECT regoper('||//');
^
SELECT regoperator('++(int4,int4)');
ERROR: operator does not exist: ++(int4,int4)
@@ -168,6 +182,10 @@ SELECT regtype('int3');
ERROR: type "int3" does not exist
LINE 1: SELECT regtype('int3');
^
+SELECT regrole('regtestrole');
+ERROR: role "regtestrole" does not exist
+LINE 1: SELECT regrole('regtestrole');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -231,6 +249,12 @@ SELECT to_regtype('int3');
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index cc90838..bc77c67 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -4,6 +4,7 @@
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
@@ -12,6 +13,7 @@ SELECT regproc('now');
SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
+SELECT regrole('regtestrole');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -19,6 +21,7 @@ SELECT to_regproc('now');
SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
+SELECT to_regrole('regtestrole');
-- with schemaname
@@ -37,6 +40,8 @@ SELECT to_regtype('pg_catalog.int4');
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
+
-- without schemaname
SELECT regoper('||//');
@@ -45,6 +50,7 @@ SELECT regproc('know');
SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
+SELECT regrole('regtestrole');
-- with schemaname
@@ -65,6 +71,7 @@ SELECT to_regproc('know');
SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
+SELECT to_regrole('regtestrole');
-- with schemaname
--
2.1.0.GIT
Sorry, I fixed a silly typo in documentation in the previous version.
- of theses types has a significance...
+ of these types has a significance...
# My fingers frequently slip as above..
I incremented the version of this revised patch to get rid of
confusion.
=======
Hello, thank you for reviewing.
The attatched are the fourth version of this patch.
0001-Add-regrole_v4.patch
0002-Add-regnamespace_v4.patch
- Rearranged into regrole patch and regnamespace patch as seen
above, each of them consists of changes for code, docs,
regtests. regnamespace patch depends on the another patch.
- Removed the irrelevant change and corrected mistakes in
comments.
- Renamed role_or_oid to role_name_or_oid in regrolein().
- Changed the example name for regrole in the docmentation to
'smithee' as an impossible-in-reality-but-well-known name, from
'john', the most common in US (according to Wikipedia).
At Tue, 24 Feb 2015 16:30:44 +0530, Jeevan Chalke <jeevan.chalke@enterprisedb.com> wrote in <CAM2+6=V-fwQFkwF0Pi3Dacq-ZRY5WxcPLVLuqFKf2Mf57_6inA@mail.gmail.com>
I agree on Tom's concern on MVCC issue, but we already hit that when we
introduced regclass and others. So I see no additional issue with these
changes as such. About planner slowness, I guess updated documentation looks
perfect for that.So I went ahead reviewing these patches.
All patches are straight forward and since we have similar code already
exists, I did not find any issue at code level. They are consistent with
other
functions.
One concern is about arbitrary allocation of OIDs for the new
objects - types, functions. They are isolated from other similar
reg* types, but there's no help for it without global renumbering
of static(system) OIDs.
Patches applies with patch -p1. make, make install, make check has
no issues. Testing was fine too.However here are few review comments on the patches attached:
Review points on 0001-Add-regrole.patch
---
1.
+#include "utils/acl.h"Can you please add it at appropriate place as #include list is an ordered
list
regrolein calls reg_role_oid in acl.c, which is declared in acl.h.
2.
+ char *role_or_oid = PG_GETARG_CSTRING(0);Can we have variable named as role_name_or_oid, like other similar
functions?
I might somehow have thought it a bit long. Fixed.
3. + /* + * Normal case: parse the name into components and see if it matches any + * pg_role entries in the current search path. + */I believe, roles are never searched per search path. Thus need to update
comments here.
Ouch. I forgot to edit it properly. I edit it. The correct
catalog name is pg_authid.
+ /* Normal case: see if the name matches any pg_authid entry. */
I also edited comments for regnamespacein.
Review points on 0002-Add-regnamespace.patch --- 1. + * regnamespacein - converts "classname" to class OIDTypos. Should be nspname instead of classname and namespase OID instead of
class OID
Thank you for pointing out. I fixed the same mistake in
regrolein, p_ts_dict was there instead of pg_authid.. The names
of oid kinds appear in multiple forms, that is, oprname and
opr_name. Although I don't understand the reason, I followed the
convention.
Review points on 0003-Check-new....patch
---
1.
@@ -1860,6 +1860,7 @@ StoreAttrDefault(Relation rel, AttrNumber attnum,
Oid attrdefOid;
ObjectAddress colobject,
defobject;
+ Oid exprtype;This seems unrelated. Please remove.
It's a trace of the previous code to ruling out the new oid
types. Removed.
Apart from this, it will be good if you have ONLY two patches,
(1) For regrole and (2) For regnamespace specific
With all related changes into one patch. I mean, all role related changes
i.e.
0001 + 0003 role related changes + 0004 role related changes and docs update
AND
0002 + 0003 nsp related changes + 0004 nsp related changes
I prudently separated it since I wasn't confident on the
pertinence of ruling out. I rearranged them as your advise
including docs.
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
The attatched are the fourth version of this patch.
0001-Add-regrole_v4.patch
0002-Add-regnamespace_v4.patch
Seems like you have missed to attach both the patches.
--
Jeevan B Chalke
Principal Software Engineer, Product Development
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
On Tue, Feb 3, 2015 at 10:12 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Two reasons this isn't terribly compelling are (1) it's creating a
join in a place where the planner can't possibly see it and optimize
it, and (2) you risk MVCC anomalies because the reg* output routines
would not be using the same snapshot as the calling query.We already have problem (2) with the existing reg* functions so I'm
not that excited about doubling down on the concept.
I think I agree. I mean, I agree that this notation is more
convenient, but I don't really want to add a whole new slough of types
--- these will certainly not be the only ones we want once we go down
this path --- to the default install just for notational convenience.
It's arguable, of course, but I guess I'm going to vote against this
patch.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 2015-03-02 16:42:35 -0500, Robert Haas wrote:
On Tue, Feb 3, 2015 at 10:12 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Two reasons this isn't terribly compelling are (1) it's creating a
join in a place where the planner can't possibly see it and optimize
it, and (2) you risk MVCC anomalies because the reg* output routines
would not be using the same snapshot as the calling query.We already have problem (2) with the existing reg* functions so I'm
not that excited about doubling down on the concept.I think I agree. I mean, I agree that this notation is more convenient, but I don't really want to add a whole new slough of types --- these will certainly not be the only ones we want once we go down this path --- to the default install just for notational convenience. It's arguable, of course, but I guess I'm going to vote against this patch.
That's a justifyable position. I don't think there are other catalogs
referenced as pervasively in the catalog though.
There's one additional point: Using reg* types in the catalog tables
themselves can make them *much* easier to read. I personally do look at
the catalogs a awful lot, and seing names instead of oids makes it much
easier. And adding regtype/role would allow to cover nearly all types
containing oids.
Incidentally I've started working on a replacement for the bki DATA
stuff
(http://archives.postgresql.org/message-id/20150220234142.GH12653%40awork2.anarazel.de)
and of the things that makes the biggest difference in editing based on
my experience is not to have to list endless columns of oids that you
have to figure out by hand. Replacing e.g. prorettype/proallargtypes
oids by their names made it much, much easier to read. And my initial
implementation simply supports that based on the column type... So
adding regnamespace/regrole actually might help there.
Greetings,
Andres Freund
--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 3/2/15 3:56 PM, Andres Freund wrote:
On 2015-03-02 16:42:35 -0500, Robert Haas wrote:
On Tue, Feb 3, 2015 at 10:12 AM, Tom Lane<tgl@sss.pgh.pa.us> wrote:
Two reasons this isn't terribly compelling are (1) it's creating a
join in a place where the planner can't possibly see it and optimize
it, and (2) you risk MVCC anomalies because the reg* output routines
would not be using the same snapshot as the calling query.We already have problem (2) with the existing reg* functions so I'm
not that excited about doubling down on the concept.I think I agree. I mean, I agree that this notation is more convenient, but I don't really want to add a whole new slough of types --- these will certainly not be the only ones we want once we go down this path --- to the default install just for notational convenience. It's arguable, of course, but I guess I'm going to vote against this patch.That's a justifyable position. I don't think there are other catalogs
referenced as pervasively in the catalog though.There's one additional point: Using reg* types in the catalog tables
themselves can make them*much* easier to read. I personally do look at
the catalogs a awful lot, and seing names instead of oids makes it much
easier. And adding regtype/role would allow to cover nearly all types
containing oids.
+1. Constantly joining catalog tables together is a royal PITA, and
regnamespace is the biggest missing part of this (I typically don't look
at roles too much, but I can certainly see it's importance).
If we had more user friendly views on the catalogs maybe this wouldn't
be an issue... but that's a much larger project.
BTW, I think the potential for MVCC issues should be mentioned in the
docs (http://www.postgresql.org/docs/devel/static/datatype-oid.html).
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello, I attached the latest patches missing in the previous mail.
Thanks for pointing Jeevan.
0001-Add-regrole_v4.patch
0002-Add-regnamespace_v4.patch
Jim> BTW, I think the potential for MVCC issues should be mentioned in the
Jim> docs (http://www.postgresql.org/docs/devel/static/datatype-oid.html).
The first patch of the aboves contains doc patch which adds the
following note to html/datatype-oid.html. Does it make sense?
Note: The OID alias types don't sctrictly comply the transaction
isolation rules so do not use them where exact transaction
isolation on the values of these types has a
significance. Likewise, since they look as simple constants to
planner so you might get slower plans than the queries joining
the system tables correnspond to the OID types.
regards,
At Mon, 2 Mar 2015 17:50:37 -0600, Jim Nasby <Jim.Nasby@BlueTreble.com> wrote in <54F4F74D.8000003@BlueTreble.com>
On 3/2/15 3:56 PM, Andres Freund wrote:
On 2015-03-02 16:42:35 -0500, Robert Haas wrote:
On Tue, Feb 3, 2015 at 10:12 AM, Tom Lane<tgl@sss.pgh.pa.us> wrote:
Two reasons this isn't terribly compelling are (1) it's creating a
join in a place where the planner can't possibly see it and optimize
it, and (2) you risk MVCC anomalies because the reg* output routines
would not be using the same snapshot as the calling query.We already have problem (2) with the existing reg* functions so I'm
not that excited about doubling down on the concept.I think I agree. I mean, I agree that this notation is more convenient, but I don't really want to add a whole new slough of types --- these will certainly not be the only ones we want once we go down this path --- to the default install just for notational convenience. It's arguable, of course, but I guess I'm going to vote against this patch.That's a justifyable position. I don't think there are other catalogs
referenced as pervasively in the catalog though.There's one additional point: Using reg* types in the catalog tables
themselves can make them*much* easier to read. I personally do look at
the catalogs a awful lot, and seing names instead of oids makes it
much
easier. And adding regtype/role would allow to cover nearly all types
containing oids.+1. Constantly joining catalog tables together is a royal PITA, and
regnamespace is the biggest missing part of this (I typically don't
look at roles too much, but I can certainly see it's importance).If we had more user friendly views on the catalogs maybe this wouldn't
be an issue... but that's a much larger project.BTW, I think the potential for MVCC issues should be mentioned in the
docs (http://www.postgresql.org/docs/devel/static/datatype-oid.html).
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
0001-Add-regrole_v4.patchtext/x-patch; charset=us-asciiDownload
>From f6c9754f190d4cfe29f776ad1fe5f1a012533924 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 18 Feb 2015 14:38:32 +0900
Subject: [PATCH 1/2] Add regrole
Add new OID aliass type regrole. The new type has the scope of whole
the database cluster so it doesn't behave as the same as the existing
OID alias types which have database scope, concerning object
dependency. To get rid of confusion, inhibit constants of the new type
from appearing where dependencies are made involving it.
Documentation about this new type is added and some existing
descriptions are modified according to the restriction of the
type. Addition to it, put a note about possible MVCC violation and
optimization issues, which are general over the all reg* types.
---
doc/src/sgml/datatype.sgml | 55 +++++++++++++-------
src/backend/bootstrap/bootstrap.c | 2 +
src/backend/catalog/dependency.c | 22 ++++++++
src/backend/utils/adt/regproc.c | 98 +++++++++++++++++++++++++++++++++++
src/backend/utils/adt/selfuncs.c | 2 +
src/backend/utils/cache/catcache.c | 1 +
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 10 ++++
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 26 +++++++++-
src/test/regress/sql/regproc.sql | 7 +++
12 files changed, 221 insertions(+), 19 deletions(-)
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index edf636b..dab5430 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4319,8 +4319,9 @@ SET xmloption TO { DOCUMENT | CONTENT };
an object identifier. There are also several alias types for
<type>oid</>: <type>regproc</>, <type>regprocedure</>,
<type>regoper</>, <type>regoperator</>, <type>regclass</>,
- <type>regtype</>, <type>regconfig</>, and <type>regdictionary</>.
- <xref linkend="datatype-oid-table"> shows an overview.
+ <type>regtype</>, <type>regrole</>, <type>regconfig</>, and
+ <type>regdictionary</>. <xref linkend="datatype-oid-table"> shows
+ an overview.
</para>
<para>
@@ -4429,6 +4430,13 @@ SELECT * FROM pg_attribute
</row>
<row>
+ <entry><type>regrole</></entry>
+ <entry><structname>pg_authid</></entry>
+ <entry>role name</entry>
+ <entry><literal>smithee</></entry>
+ </row>
+
+ <row>
<entry><type>regconfig</></entry>
<entry><structname>pg_ts_config</></entry>
<entry>text search configuration</entry>
@@ -4446,29 +4454,40 @@ SELECT * FROM pg_attribute
</table>
<para>
- All of the OID alias types accept schema-qualified names, and will
- display schema-qualified names on output if the object would not
- be found in the current search path without being qualified.
- The <type>regproc</> and <type>regoper</> alias types will only
- accept input names that are unique (not overloaded), so they are
- of limited use; for most uses <type>regprocedure</> or
+ All of the OID alias types for objects grouped by namespace accept
+ schema-qualified names, and will display schema-qualified names on output
+ if the object would not be found in the current search path without being
+ qualified. The <type>regproc</> and <type>regoper</> alias types will
+ only accept input names that are unique (not overloaded), so they are of
+ limited use; for most uses <type>regprocedure</> or
<type>regoperator</> are more appropriate. For <type>regoperator</>,
unary operators are identified by writing <literal>NONE</> for the unused
operand.
</para>
<para>
- An additional property of the OID alias types is the creation of
- dependencies. If a
- constant of one of these types appears in a stored expression
- (such as a column default expression or view), it creates a dependency
- on the referenced object. For example, if a column has a default
- expression <literal>nextval('my_seq'::regclass)</>,
- <productname>PostgreSQL</productname>
- understands that the default expression depends on the sequence
- <literal>my_seq</>; the system will not let the sequence be dropped
- without first removing the default expression.
+ An additional property of most of the OID alias types is the creation of
+ dependencies. If a constant of one of these types appears in a stored
+ expression (such as a column default expression or view), it creates a
+ dependency on the referenced object. For example, if a column has
+ a default expression <literal>nextval('my_seq'::regclass)</>,
+ <productname>PostgreSQL</productname> understands that the default
+ expression depends on the sequence <literal>my_seq</>; the system
+ will not let the sequence be dropped without first removing the
+ default expression. <type>regrole</> is the exception for the
+ property. Constants of this type are not allowed in such
+ expressions.
+ </para>
+
+ <note>
+ <para>
+ The OID alias types don't sctrictly comply the transaction isolation
+ rules so do not use them where exact transaction isolation on the values
+ of these types has a significance. Likewise, since they look as simple
+ constants to planner so you might get slower plans than the queries
+ joining the system tables correnspond to the OID types.
</para>
+ </note>
<para>
Another identifier type used by the system is <type>xid</>, or transaction
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index ad49964..c375c96 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -113,6 +113,8 @@ static const struct typinfo TypInfo[] = {
F_REGPROCIN, F_REGPROCOUT},
{"regtype", REGTYPEOID, 0, 4, true, 'i', 'p', InvalidOid,
F_REGTYPEIN, F_REGTYPEOUT},
+ {"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
+ F_REGROLEIN, F_REGROLEOUT},
{"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index bacb242..c85f70a 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1597,6 +1597,28 @@ find_expr_references_walker(Node *node,
add_object_address(OCLASS_TSDICT, objoid, 0,
context->addrs);
break;
+
+ /*
+ * Dependencies for regrole in expressions are not handled as
+ * same as other reg* types. So explicitly inhibit the usage
+ * to get rid of confusions.
+ */
+ case REGROLEOID:
+ {
+ HeapTuple tt;
+ char *typename = "<unknown>";
+
+ tt = SearchSysCache1(TYPEOID, con->consttype);
+ if (HeapTupleIsValid(tt))
+ typename = pstrdup(NameStr(((Form_pg_type)
+ GETSTRUCT(tt))->typname));
+ ReleaseSysCache(tt);
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("constant of the type \'%s\' cannot be used here",
+ typename)));
+ }
+ break;
}
}
return false;
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 3d1bb32..a5196e7 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -40,6 +40,7 @@
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/tqual.h"
+#include "utils/acl.h"
static char *format_operator_internal(Oid operator_oid, bool force_qualify);
static char *format_procedure_internal(Oid procedure_oid, bool force_qualify);
@@ -1553,6 +1554,103 @@ regdictionarysend(PG_FUNCTION_ARGS)
return oidsend(fcinfo);
}
+/*
+ * regrolein - converts "rolename" to role OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_authid entry.
+ *
+ * This function is not needed in bootstrap mode, so we don't worry about
+ * making it work then.
+ */
+Datum
+regrolein(PG_FUNCTION_ARGS)
+{
+ char *role_name_or_oid = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ /* '-' ? */
+ if (strcmp(role_name_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (role_name_or_oid[0] >= '0' &&
+ role_name_or_oid[0] <= '9' &&
+ strspn(role_name_or_oid, "0123456789") == strlen(role_name_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(role_name_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /* Normal case: see if the name matches any pg_authid entry. */
+ result = get_role_oid(role_name_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regrole - converts "rolename" to role OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regrole(PG_FUNCTION_ARGS)
+{
+ char *role_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_role_oid(role_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regroleout - converts role OID to "role_name"
+ */
+Datum
+regroleout(PG_FUNCTION_ARGS)
+{
+ Oid roleoid = PG_GETARG_OID(0);
+ char *result;
+
+
+ if (roleoid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = GetUserNameFromId(roleoid);
+ PG_RETURN_CSTRING(result);
+}
+
+/*
+ * regrolerecv - converts external binary format to regrole
+ */
+Datum
+regrolerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regrolesend - converts regrole to binary format
+ */
+Datum
+regrolesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
+
+
/*
* text_regclass: convert text to regclass
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 1ba103c..529b0ed 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3619,6 +3619,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
*scaledvalue = convert_numeric_to_scalar(value, valuetypid);
*scaledlobound = convert_numeric_to_scalar(lobound, boundstypid);
*scaledhibound = convert_numeric_to_scalar(hibound, boundstypid);
@@ -3724,6 +3725,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
/* we can treat OIDs as integers... */
return (double) DatumGetObjectId(value);
}
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 1af43c6..9b7cc5e 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -150,6 +150,7 @@ GetCCHashEqFuncs(Oid keytype, PGFunction *hashfunc, RegProcedure *eqfunc)
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
*hashfunc = hashoid;
*eqfunc = F_OIDEQ;
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index b314369..bc0faa8 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -210,6 +210,13 @@ DATA(insert ( 3769 20 1288 a f ));
DATA(insert ( 3769 23 0 a b ));
DATA(insert ( 25 2205 1079 i f ));
DATA(insert ( 1043 2205 1079 i f ));
+DATA(insert ( 26 4096 0 i b ));
+DATA(insert ( 4096 26 0 i b ));
+DATA(insert ( 20 4096 1287 i f ));
+DATA(insert ( 21 4096 313 i f ));
+DATA(insert ( 23 4096 0 i b ));
+DATA(insert ( 4096 20 1288 a f ));
+DATA(insert ( 4096 23 0 a b ));
/*
* String category
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 4268b99..2aa7c33 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3438,6 +3438,12 @@ DESCR("convert type name to regtype");
DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "25" _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ ));
DESCR("convert text to regclass");
+DATA(insert OID = 4091 ( regrolein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ regrolein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4096" _null_ _null_ _null_ _null_ regroleout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
+DESCR("convert role name to regrole");
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
DESCR("(internal)");
DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
@@ -3833,6 +3839,10 @@ DATA(insert OID = 2454 ( regtyperecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1
DESCR("I/O");
DATA(insert OID = 2455 ( regtypesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2206" _null_ _null_ _null_ _null_ regtypesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4096 "2281" _null_ _null_ _null_ _null_ regrolerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 0a900dd..1430bc1 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -564,12 +564,17 @@ DATA(insert OID = 2206 ( regtype PGNSP PGUID 4 t b N f t \054 0 0 2211 regty
DESCR("registered type");
#define REGTYPEOID 2206
+DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 regrolein regroleout regrolerecv regrolesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered role");
+#define REGROLEOID 4096
+
DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
+DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index bc4517d..0e1e99e 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -630,6 +630,11 @@ extern Datum regtypeout(PG_FUNCTION_ARGS);
extern Datum regtyperecv(PG_FUNCTION_ARGS);
extern Datum regtypesend(PG_FUNCTION_ARGS);
extern Datum to_regtype(PG_FUNCTION_ARGS);
+extern Datum regrolein(PG_FUNCTION_ARGS);
+extern Datum regroleout(PG_FUNCTION_ARGS);
+extern Datum regrolerecv(PG_FUNCTION_ARGS);
+extern Datum regrolesend(PG_FUNCTION_ARGS);
+extern Datum to_regrole(PG_FUNCTION_ARGS);
extern Datum regconfigin(PG_FUNCTION_ARGS);
extern Datum regconfigout(PG_FUNCTION_ARGS);
extern Datum regconfigrecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index 3342129..beda8ec 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -2,6 +2,7 @@
-- regproc
--
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
regoper
@@ -39,6 +40,12 @@ SELECT regtype('int4');
integer
(1 row)
+SELECT regrole('regtestrole');
+ regrole
+-------------
+ regtestrole
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -75,6 +82,12 @@ SELECT to_regtype('int4');
integer
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+-------------
+ regtestrole
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -143,10 +156,11 @@ SELECT to_regtype('pg_catalog.int4');
(1 row)
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
-- without schemaname
SELECT regoper('||//');
ERROR: operator does not exist: ||//
-LINE 3: SELECT regoper('||//');
+LINE 1: SELECT regoper('||//');
^
SELECT regoperator('++(int4,int4)');
ERROR: operator does not exist: ++(int4,int4)
@@ -168,6 +182,10 @@ SELECT regtype('int3');
ERROR: type "int3" does not exist
LINE 1: SELECT regtype('int3');
^
+SELECT regrole('regtestrole');
+ERROR: role "regtestrole" does not exist
+LINE 1: SELECT regrole('regtestrole');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -231,6 +249,12 @@ SELECT to_regtype('int3');
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index cc90838..bc77c67 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -4,6 +4,7 @@
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
@@ -12,6 +13,7 @@ SELECT regproc('now');
SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
+SELECT regrole('regtestrole');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -19,6 +21,7 @@ SELECT to_regproc('now');
SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
+SELECT to_regrole('regtestrole');
-- with schemaname
@@ -37,6 +40,8 @@ SELECT to_regtype('pg_catalog.int4');
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
+
-- without schemaname
SELECT regoper('||//');
@@ -45,6 +50,7 @@ SELECT regproc('know');
SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
+SELECT regrole('regtestrole');
-- with schemaname
@@ -65,6 +71,7 @@ SELECT to_regproc('know');
SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
+SELECT to_regrole('regtestrole');
-- with schemaname
--
2.1.0.GIT
0002-Add-regnamespace_v4.patchtext/x-patch; charset=us-asciiDownload
>From 4e22468cf1d6f13e0d6d959ede783529ac5f3828 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Thu, 26 Feb 2015 18:10:41 +0900
Subject: [PATCH 2/2] Add regnamespace.
Added new OID alias type regnamespace, and edited related documents.
---
doc/src/sgml/datatype.sgml | 19 ++++---
src/backend/bootstrap/bootstrap.c | 2 +
src/backend/catalog/dependency.c | 7 +--
src/backend/utils/adt/regproc.c | 93 +++++++++++++++++++++++++++++++++++
src/backend/utils/adt/selfuncs.c | 2 +
src/backend/utils/cache/catcache.c | 1 +
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 10 ++++
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 22 +++++++++
src/test/regress/sql/regproc.sql | 4 ++
12 files changed, 168 insertions(+), 9 deletions(-)
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index dab5430..71d9ec9 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4319,9 +4319,9 @@ SET xmloption TO { DOCUMENT | CONTENT };
an object identifier. There are also several alias types for
<type>oid</>: <type>regproc</>, <type>regprocedure</>,
<type>regoper</>, <type>regoperator</>, <type>regclass</>,
- <type>regtype</>, <type>regrole</>, <type>regconfig</>, and
- <type>regdictionary</>. <xref linkend="datatype-oid-table"> shows
- an overview.
+ <type>regtype</>, <type>regrole</>, <type>regnamespace</>,
+ <type>regconfig</>, and <type>regdictionary</>.
+ <xref linkend="datatype-oid-table"> shows an overview.
</para>
<para>
@@ -4437,6 +4437,13 @@ SELECT * FROM pg_attribute
</row>
<row>
+ <entry><type>regnamespace</></entry>
+ <entry><structname>pg_namespace</></entry>
+ <entry>namespace name</entry>
+ <entry><literal>pg_catalog</></entry>
+ </row>
+
+ <row>
<entry><type>regconfig</></entry>
<entry><structname>pg_ts_config</></entry>
<entry>text search configuration</entry>
@@ -4474,9 +4481,9 @@ SELECT * FROM pg_attribute
<productname>PostgreSQL</productname> understands that the default
expression depends on the sequence <literal>my_seq</>; the system
will not let the sequence be dropped without first removing the
- default expression. <type>regrole</> is the exception for the
- property. Constants of this type are not allowed in such
- expressions.
+ default expression. <type>regrole</> and <type>regnamespace</> are
+ the exceptions for the property. Constants of these types are not
+ allowed in such expressions.
</para>
<note>
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index c375c96..f30d5e6 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -115,6 +115,8 @@ static const struct typinfo TypInfo[] = {
F_REGTYPEIN, F_REGTYPEOUT},
{"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
F_REGROLEIN, F_REGROLEOUT},
+ {"regnamespace", REGNAMESPACEOID, 0, 4, true, 'i', 'p', InvalidOid,
+ F_REGNAMESPACEIN, F_REGNAMESPACEOUT},
{"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index c85f70a..a59c2cd 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1599,11 +1599,12 @@ find_expr_references_walker(Node *node,
break;
/*
- * Dependencies for regrole in expressions are not handled as
- * same as other reg* types. So explicitly inhibit the usage
- * to get rid of confusions.
+ * Dependencies for regrole and regnamespace in expressions
+ * are not handled as same as other reg* types. So explicitly
+ * inhibit the usage to get rid of confusions.
*/
case REGROLEOID:
+ case REGNAMESPACEOID:
{
HeapTuple tt;
char *typename = "<unknown>";
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index a5196e7..d367e5e 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -1650,7 +1650,100 @@ regrolesend(PG_FUNCTION_ARGS)
return oidsend(fcinfo);
}
+/*
+ * regnamespacein - converts "nspname" to namespace OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_namespace entry.
+ */
+Datum
+regnamespacein(PG_FUNCTION_ARGS)
+{
+ char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
+ Oid result = InvalidOid;
+
+ /* '-' ? */
+ if (strcmp(nsp_name_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (nsp_name_or_oid[0] >= '0' &&
+ nsp_name_or_oid[0] <= '9' &&
+ strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(nsp_name_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /* Normal case: see if the name matches any pg_namespace entry. */
+ result = get_namespace_oid(nsp_name_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regnamespace - converts "nspname" to namespace OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regnamespace(PG_FUNCTION_ARGS)
+{
+ char *nsp_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_namespace_oid(nsp_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regnamespaceout - converts namespace OID to "nsp_name"
+ */
+Datum
+regnamespaceout(PG_FUNCTION_ARGS)
+{
+ Oid nspid = PG_GETARG_OID(0);
+ char *result;
+
+ if (nspid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = get_namespace_name(nspid);
+ if (result)
+ PG_RETURN_CSTRING(result);
+ else
+ PG_RETURN_NULL();
+}
+/*
+ * regnamespacerecv - converts external binary format to regnamespace
+ */
+Datum
+regnamespacerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regnamespacesend - converts regnamespace to binary format
+ */
+Datum
+regnamespacesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
/*
* text_regclass: convert text to regclass
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 529b0ed..1761729 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3620,6 +3620,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
*scaledvalue = convert_numeric_to_scalar(value, valuetypid);
*scaledlobound = convert_numeric_to_scalar(lobound, boundstypid);
*scaledhibound = convert_numeric_to_scalar(hibound, boundstypid);
@@ -3726,6 +3727,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
/* we can treat OIDs as integers... */
return (double) DatumGetObjectId(value);
}
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 9b7cc5e..5bb03dd 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -151,6 +151,7 @@ GetCCHashEqFuncs(Oid keytype, PGFunction *hashfunc, RegProcedure *eqfunc)
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
*hashfunc = hashoid;
*eqfunc = F_OIDEQ;
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index bc0faa8..5337619 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -217,6 +217,13 @@ DATA(insert ( 21 4096 313 i f ));
DATA(insert ( 23 4096 0 i b ));
DATA(insert ( 4096 20 1288 a f ));
DATA(insert ( 4096 23 0 a b ));
+DATA(insert ( 26 4089 0 i b ));
+DATA(insert ( 4089 26 0 i b ));
+DATA(insert ( 20 4089 1287 i f ));
+DATA(insert ( 21 4089 313 i f ));
+DATA(insert ( 23 4089 0 i b ));
+DATA(insert ( 4089 20 1288 a f ));
+DATA(insert ( 4089 23 0 a b ));
/*
* String category
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 2aa7c33..ff90781 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3444,6 +3444,12 @@ DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2
DESCR("I/O");
DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
DESCR("convert role name to regrole");
+DATA(insert OID = 4084 ( regnamespacein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ regnamespacein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4085 ( regnamespaceout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4089" _null_ _null_ _null_ _null_ regnamespaceout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4086 ( to_regnamespace PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ to_regnamespace _null_ _null_ _null_ ));
+DESCR("convert namespace name to regnamespace");
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
DESCR("(internal)");
DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
@@ -3843,6 +3849,10 @@ DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i
DESCR("I/O");
DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4087 ( regnamespacerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4089 "2281" _null_ _null_ _null_ _null_ regnamespacerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4088 ( regnamespacesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4089" _null_ _null_ _null_ _null_ regnamespacesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 1430bc1..2493353 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -568,6 +568,10 @@ DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 re
DESCR("registered role");
#define REGROLEOID 4096
+DATA(insert OID = 4089 ( regnamespace PGNSP PGUID 4 t b N f t \054 0 0 4090 regnamespacein regnamespaceout regnamespacerecv regnamespacesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered namespace");
+#define REGNAMESPACEOID 4089
+
DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
@@ -575,6 +579,7 @@ DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 arr
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
+DATA(insert OID = 4090 ( _regnamespace PGNSP PGUID -1 f b A f t \054 0 4089 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 0e1e99e..7b3c162 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -635,6 +635,11 @@ extern Datum regroleout(PG_FUNCTION_ARGS);
extern Datum regrolerecv(PG_FUNCTION_ARGS);
extern Datum regrolesend(PG_FUNCTION_ARGS);
extern Datum to_regrole(PG_FUNCTION_ARGS);
+extern Datum regnamespacein(PG_FUNCTION_ARGS);
+extern Datum regnamespaceout(PG_FUNCTION_ARGS);
+extern Datum regnamespacerecv(PG_FUNCTION_ARGS);
+extern Datum regnamespacesend(PG_FUNCTION_ARGS);
+extern Datum to_regnamespace(PG_FUNCTION_ARGS);
extern Datum regconfigin(PG_FUNCTION_ARGS);
extern Datum regconfigout(PG_FUNCTION_ARGS);
extern Datum regconfigrecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index beda8ec..8c734f4 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -46,6 +46,12 @@ SELECT regrole('regtestrole');
regtestrole
(1 row)
+SELECT regnamespace('pg_catalog');
+ regnamespace
+--------------
+ pg_catalog
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -88,6 +94,12 @@ SELECT to_regrole('regtestrole');
regtestrole
(1 row)
+SELECT to_regnamespace('pg_catalog');
+ to_regnamespace
+-----------------
+ pg_catalog
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -186,6 +198,10 @@ SELECT regrole('regtestrole');
ERROR: role "regtestrole" does not exist
LINE 1: SELECT regrole('regtestrole');
^
+SELECT regnamespace('nonexistent');
+ERROR: schema "nonexistent" does not exist
+LINE 1: SELECT regnamespace('nonexistent');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -255,6 +271,12 @@ SELECT to_regrole('regtestrole');
(1 row)
+SELECT to_regnamespace('nonexistent');
+ to_regnamespace
+-----------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index bc77c67..8edaf15 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -14,6 +14,7 @@ SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
SELECT regrole('regtestrole');
+SELECT regnamespace('pg_catalog');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -22,6 +23,7 @@ SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
SELECT to_regrole('regtestrole');
+SELECT to_regnamespace('pg_catalog');
-- with schemaname
@@ -51,6 +53,7 @@ SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
SELECT regrole('regtestrole');
+SELECT regnamespace('nonexistent');
-- with schemaname
@@ -72,6 +75,7 @@ SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
SELECT to_regrole('regtestrole');
+SELECT to_regnamespace('nonexistent');
-- with schemaname
--
2.1.0.GIT
On 3/3/15 8:04 PM, Kyotaro HORIGUCHI wrote:
Note: The OID alias types don't sctrictly comply the transaction
isolation rules so do not use them where exact transaction
isolation on the values of these types has a
significance. Likewise, since they look as simple constants to
planner so you might get slower plans than the queries joining
the system tables correnspond to the OID types.
Might I suggest:
Note: The OID alias types do not completely follow transaction isolation
rules. The planner also treats them as simple constants, which may
result in sub-optimal planning.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passed
1.
+#include "utils/acl.h"Can you please add it at appropriate place as #include list is an ordered
list
regrolein calls reg_role_oid in acl.c, which is declared in acl.h.
Well. I was suggesting that putting #include "utils/acl.h" line after
#include "parser/parse_type.h" and before #include "utils/builtins.h"
so that they will be in order.
I understand that it is needed for reg_role_oid() call.
Review comments on *_v4 patches:
1.
+ The OID alias types don't sctrictly comply the transaction isolation
Typo. sctrictly => strictly
2.
+ joining the system tables correnspond to the OID types.
Typo. correnspond => correspond
Apart from these typos, I see no issues.
However, you can have a look over Jim's suggestion on doc wordings.
If you feel comfortable, I have no issues if you mark this as
"Ready for Committer" once you fix the typos and doc wordings.
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Thank you for the correction.
At Wed, 4 Mar 2015 01:01:48 -0600, Jim Nasby <Jim.Nasby@BlueTreble.com> wrote in <54F6ADDC.8030201@BlueTreble.com>
On 3/3/15 8:04 PM, Kyotaro HORIGUCHI wrote:
Note: The OID alias types don't sctrictly comply the transaction
isolation rules so do not use them where exact transaction
isolation on the values of these types has a
significance. Likewise, since they look as simple constants to
planner so you might get slower plans than the queries joining
the system tables correnspond to the OID types.Might I suggest:
Note: The OID alias types do not completely follow transaction
isolation rules. The planner also treats them as simple constants,
which may result in sub-optimal planning.
Looks far simple and enough.
The note has been replaced with your sentence in the attached patch.
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
0001-Add-regrole_v5.patchtext/x-patch; charset=us-asciiDownload
>From e31c326fa8e8ee294f003258233bf4be1410fdd4 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Wed, 18 Feb 2015 14:38:32 +0900
Subject: [PATCH 1/2] Add regrole
Add new OID aliass type regrole. The new type has the scope of whole
the database cluster so it doesn't behave as the same as the existing
OID alias types which have database scope, concerning object
dependency. To get rid of confusion, inhibit constants of the new type
from appearing where dependencies are made involving it.
Documentation about this new type is added and some existing
descriptions are modified according to the restriction of the
type. Addition to it, put a note about possible MVCC violation and
optimization issues, which are general over the all reg* types.
---
doc/src/sgml/datatype.sgml | 53 ++++++++++++-------
src/backend/bootstrap/bootstrap.c | 2 +
src/backend/catalog/dependency.c | 22 ++++++++
src/backend/utils/adt/regproc.c | 98 +++++++++++++++++++++++++++++++++++
src/backend/utils/adt/selfuncs.c | 2 +
src/backend/utils/cache/catcache.c | 1 +
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 10 ++++
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 26 +++++++++-
src/test/regress/sql/regproc.sql | 7 +++
12 files changed, 219 insertions(+), 19 deletions(-)
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index edf636b..f4e82f5 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4319,8 +4319,9 @@ SET xmloption TO { DOCUMENT | CONTENT };
an object identifier. There are also several alias types for
<type>oid</>: <type>regproc</>, <type>regprocedure</>,
<type>regoper</>, <type>regoperator</>, <type>regclass</>,
- <type>regtype</>, <type>regconfig</>, and <type>regdictionary</>.
- <xref linkend="datatype-oid-table"> shows an overview.
+ <type>regtype</>, <type>regrole</>, <type>regconfig</>, and
+ <type>regdictionary</>. <xref linkend="datatype-oid-table"> shows
+ an overview.
</para>
<para>
@@ -4429,6 +4430,13 @@ SELECT * FROM pg_attribute
</row>
<row>
+ <entry><type>regrole</></entry>
+ <entry><structname>pg_authid</></entry>
+ <entry>role name</entry>
+ <entry><literal>smithee</></entry>
+ </row>
+
+ <row>
<entry><type>regconfig</></entry>
<entry><structname>pg_ts_config</></entry>
<entry>text search configuration</entry>
@@ -4446,29 +4454,38 @@ SELECT * FROM pg_attribute
</table>
<para>
- All of the OID alias types accept schema-qualified names, and will
- display schema-qualified names on output if the object would not
- be found in the current search path without being qualified.
- The <type>regproc</> and <type>regoper</> alias types will only
- accept input names that are unique (not overloaded), so they are
- of limited use; for most uses <type>regprocedure</> or
+ All of the OID alias types for objects grouped by namespace accept
+ schema-qualified names, and will display schema-qualified names on output
+ if the object would not be found in the current search path without being
+ qualified. The <type>regproc</> and <type>regoper</> alias types will
+ only accept input names that are unique (not overloaded), so they are of
+ limited use; for most uses <type>regprocedure</> or
<type>regoperator</> are more appropriate. For <type>regoperator</>,
unary operators are identified by writing <literal>NONE</> for the unused
operand.
</para>
<para>
- An additional property of the OID alias types is the creation of
- dependencies. If a
- constant of one of these types appears in a stored expression
- (such as a column default expression or view), it creates a dependency
- on the referenced object. For example, if a column has a default
- expression <literal>nextval('my_seq'::regclass)</>,
- <productname>PostgreSQL</productname>
- understands that the default expression depends on the sequence
- <literal>my_seq</>; the system will not let the sequence be dropped
- without first removing the default expression.
+ An additional property of most of the OID alias types is the creation of
+ dependencies. If a constant of one of these types appears in a stored
+ expression (such as a column default expression or view), it creates a
+ dependency on the referenced object. For example, if a column has
+ a default expression <literal>nextval('my_seq'::regclass)</>,
+ <productname>PostgreSQL</productname> understands that the default
+ expression depends on the sequence <literal>my_seq</>; the system
+ will not let the sequence be dropped without first removing the
+ default expression. <type>regrole</> is the exception for the
+ property. Constants of this type are not allowed in such
+ expressions.
+ </para>
+
+ <note>
+ <para>
+ The OID alias types do not completely follow transaction isolation
+ rules. The planner also treats them as simple constants, which may
+ result in sub-optimal planning.
</para>
+ </note>
<para>
Another identifier type used by the system is <type>xid</>, or transaction
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index ad49964..c375c96 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -113,6 +113,8 @@ static const struct typinfo TypInfo[] = {
F_REGPROCIN, F_REGPROCOUT},
{"regtype", REGTYPEOID, 0, 4, true, 'i', 'p', InvalidOid,
F_REGTYPEIN, F_REGTYPEOUT},
+ {"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
+ F_REGROLEIN, F_REGROLEOUT},
{"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index bacb242..c85f70a 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1597,6 +1597,28 @@ find_expr_references_walker(Node *node,
add_object_address(OCLASS_TSDICT, objoid, 0,
context->addrs);
break;
+
+ /*
+ * Dependencies for regrole in expressions are not handled as
+ * same as other reg* types. So explicitly inhibit the usage
+ * to get rid of confusions.
+ */
+ case REGROLEOID:
+ {
+ HeapTuple tt;
+ char *typename = "<unknown>";
+
+ tt = SearchSysCache1(TYPEOID, con->consttype);
+ if (HeapTupleIsValid(tt))
+ typename = pstrdup(NameStr(((Form_pg_type)
+ GETSTRUCT(tt))->typname));
+ ReleaseSysCache(tt);
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("constant of the type \'%s\' cannot be used here",
+ typename)));
+ }
+ break;
}
}
return false;
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index 3d1bb32..a5196e7 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -40,6 +40,7 @@
#include "utils/lsyscache.h"
#include "utils/syscache.h"
#include "utils/tqual.h"
+#include "utils/acl.h"
static char *format_operator_internal(Oid operator_oid, bool force_qualify);
static char *format_procedure_internal(Oid procedure_oid, bool force_qualify);
@@ -1553,6 +1554,103 @@ regdictionarysend(PG_FUNCTION_ARGS)
return oidsend(fcinfo);
}
+/*
+ * regrolein - converts "rolename" to role OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_authid entry.
+ *
+ * This function is not needed in bootstrap mode, so we don't worry about
+ * making it work then.
+ */
+Datum
+regrolein(PG_FUNCTION_ARGS)
+{
+ char *role_name_or_oid = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ /* '-' ? */
+ if (strcmp(role_name_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (role_name_or_oid[0] >= '0' &&
+ role_name_or_oid[0] <= '9' &&
+ strspn(role_name_or_oid, "0123456789") == strlen(role_name_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(role_name_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /* Normal case: see if the name matches any pg_authid entry. */
+ result = get_role_oid(role_name_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regrole - converts "rolename" to role OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regrole(PG_FUNCTION_ARGS)
+{
+ char *role_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_role_oid(role_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regroleout - converts role OID to "role_name"
+ */
+Datum
+regroleout(PG_FUNCTION_ARGS)
+{
+ Oid roleoid = PG_GETARG_OID(0);
+ char *result;
+
+
+ if (roleoid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = GetUserNameFromId(roleoid);
+ PG_RETURN_CSTRING(result);
+}
+
+/*
+ * regrolerecv - converts external binary format to regrole
+ */
+Datum
+regrolerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regrolesend - converts regrole to binary format
+ */
+Datum
+regrolesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
+
+
/*
* text_regclass: convert text to regclass
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index 4dd3f9f..a28868c 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3619,6 +3619,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
*scaledvalue = convert_numeric_to_scalar(value, valuetypid);
*scaledlobound = convert_numeric_to_scalar(lobound, boundstypid);
*scaledhibound = convert_numeric_to_scalar(hibound, boundstypid);
@@ -3724,6 +3725,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
/* we can treat OIDs as integers... */
return (double) DatumGetObjectId(value);
}
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 1af43c6..9b7cc5e 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -150,6 +150,7 @@ GetCCHashEqFuncs(Oid keytype, PGFunction *hashfunc, RegProcedure *eqfunc)
case REGTYPEOID:
case REGCONFIGOID:
case REGDICTIONARYOID:
+ case REGROLEOID:
*hashfunc = hashoid;
*eqfunc = F_OIDEQ;
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index c49fe26..9e8cb1c 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -210,6 +210,13 @@ DATA(insert ( 3769 20 1288 a f ));
DATA(insert ( 3769 23 0 a b ));
DATA(insert ( 25 2205 1079 i f ));
DATA(insert ( 1043 2205 1079 i f ));
+DATA(insert ( 26 4096 0 i b ));
+DATA(insert ( 4096 26 0 i b ));
+DATA(insert ( 20 4096 1287 i f ));
+DATA(insert ( 21 4096 313 i f ));
+DATA(insert ( 23 4096 0 i b ));
+DATA(insert ( 4096 20 1288 a f ));
+DATA(insert ( 4096 23 0 a b ));
/*
* String category
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index b8a3660..7cdf8c2 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3442,6 +3442,12 @@ DESCR("convert type name to regtype");
DATA(insert OID = 1079 ( regclass PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2205 "25" _null_ _null_ _null_ _null_ text_regclass _null_ _null_ _null_ ));
DESCR("convert text to regclass");
+DATA(insert OID = 4091 ( regrolein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ regrolein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4096" _null_ _null_ _null_ _null_ regroleout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
+DESCR("convert role name to regrole");
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
DESCR("(internal)");
DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
@@ -3837,6 +3843,10 @@ DATA(insert OID = 2454 ( regtyperecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1
DESCR("I/O");
DATA(insert OID = 2455 ( regtypesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "2206" _null_ _null_ _null_ _null_ regtypesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4096 "2281" _null_ _null_ _null_ _null_ regrolerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 0a900dd..1430bc1 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -564,12 +564,17 @@ DATA(insert OID = 2206 ( regtype PGNSP PGUID 4 t b N f t \054 0 0 2211 regty
DESCR("registered type");
#define REGTYPEOID 2206
+DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 regrolein regroleout regrolerecv regrolesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered role");
+#define REGROLEOID 4096
+
DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
+DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index bc4517d..0e1e99e 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -630,6 +630,11 @@ extern Datum regtypeout(PG_FUNCTION_ARGS);
extern Datum regtyperecv(PG_FUNCTION_ARGS);
extern Datum regtypesend(PG_FUNCTION_ARGS);
extern Datum to_regtype(PG_FUNCTION_ARGS);
+extern Datum regrolein(PG_FUNCTION_ARGS);
+extern Datum regroleout(PG_FUNCTION_ARGS);
+extern Datum regrolerecv(PG_FUNCTION_ARGS);
+extern Datum regrolesend(PG_FUNCTION_ARGS);
+extern Datum to_regrole(PG_FUNCTION_ARGS);
extern Datum regconfigin(PG_FUNCTION_ARGS);
extern Datum regconfigout(PG_FUNCTION_ARGS);
extern Datum regconfigrecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index 3342129..beda8ec 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -2,6 +2,7 @@
-- regproc
--
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
regoper
@@ -39,6 +40,12 @@ SELECT regtype('int4');
integer
(1 row)
+SELECT regrole('regtestrole');
+ regrole
+-------------
+ regtestrole
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -75,6 +82,12 @@ SELECT to_regtype('int4');
integer
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+-------------
+ regtestrole
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -143,10 +156,11 @@ SELECT to_regtype('pg_catalog.int4');
(1 row)
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
-- without schemaname
SELECT regoper('||//');
ERROR: operator does not exist: ||//
-LINE 3: SELECT regoper('||//');
+LINE 1: SELECT regoper('||//');
^
SELECT regoperator('++(int4,int4)');
ERROR: operator does not exist: ++(int4,int4)
@@ -168,6 +182,10 @@ SELECT regtype('int3');
ERROR: type "int3" does not exist
LINE 1: SELECT regtype('int3');
^
+SELECT regrole('regtestrole');
+ERROR: role "regtestrole" does not exist
+LINE 1: SELECT regrole('regtestrole');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -231,6 +249,12 @@ SELECT to_regtype('int3');
(1 row)
+SELECT to_regrole('regtestrole');
+ to_regrole
+------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index cc90838..bc77c67 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -4,6 +4,7 @@
/* If objects exist, return oids */
+CREATE ROLE regtestrole;
-- without schemaname
SELECT regoper('||/');
@@ -12,6 +13,7 @@ SELECT regproc('now');
SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
+SELECT regrole('regtestrole');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -19,6 +21,7 @@ SELECT to_regproc('now');
SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
+SELECT to_regrole('regtestrole');
-- with schemaname
@@ -37,6 +40,8 @@ SELECT to_regtype('pg_catalog.int4');
/* If objects don't exist, raise errors. */
+DROP ROLE regtestrole;
+
-- without schemaname
SELECT regoper('||//');
@@ -45,6 +50,7 @@ SELECT regproc('know');
SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
+SELECT regrole('regtestrole');
-- with schemaname
@@ -65,6 +71,7 @@ SELECT to_regproc('know');
SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
+SELECT to_regrole('regtestrole');
-- with schemaname
--
2.1.0.GIT
0002-Add-regnamespace_v5.patchtext/x-patch; charset=us-asciiDownload
>From 1afab09905ae7c3f0070a2f48816c7662e574b62 Mon Sep 17 00:00:00 2001
From: Kyotaro Horiguchi <horiguchi.kyotaro@lab.ntt.co.jp>
Date: Thu, 26 Feb 2015 18:10:41 +0900
Subject: [PATCH 2/2] Add regnamespace.
Added new OID alias type regnamespace, and edited related documents.
---
doc/src/sgml/datatype.sgml | 19 ++++---
src/backend/bootstrap/bootstrap.c | 2 +
src/backend/catalog/dependency.c | 7 +--
src/backend/utils/adt/regproc.c | 93 +++++++++++++++++++++++++++++++++++
src/backend/utils/adt/selfuncs.c | 2 +
src/backend/utils/cache/catcache.c | 1 +
src/include/catalog/pg_cast.h | 7 +++
src/include/catalog/pg_proc.h | 10 ++++
src/include/catalog/pg_type.h | 5 ++
src/include/utils/builtins.h | 5 ++
src/test/regress/expected/regproc.out | 22 +++++++++
src/test/regress/sql/regproc.sql | 4 ++
12 files changed, 168 insertions(+), 9 deletions(-)
diff --git a/doc/src/sgml/datatype.sgml b/doc/src/sgml/datatype.sgml
index f4e82f5..2a643cf 100644
--- a/doc/src/sgml/datatype.sgml
+++ b/doc/src/sgml/datatype.sgml
@@ -4319,9 +4319,9 @@ SET xmloption TO { DOCUMENT | CONTENT };
an object identifier. There are also several alias types for
<type>oid</>: <type>regproc</>, <type>regprocedure</>,
<type>regoper</>, <type>regoperator</>, <type>regclass</>,
- <type>regtype</>, <type>regrole</>, <type>regconfig</>, and
- <type>regdictionary</>. <xref linkend="datatype-oid-table"> shows
- an overview.
+ <type>regtype</>, <type>regrole</>, <type>regnamespace</>,
+ <type>regconfig</>, and <type>regdictionary</>.
+ <xref linkend="datatype-oid-table"> shows an overview.
</para>
<para>
@@ -4437,6 +4437,13 @@ SELECT * FROM pg_attribute
</row>
<row>
+ <entry><type>regnamespace</></entry>
+ <entry><structname>pg_namespace</></entry>
+ <entry>namespace name</entry>
+ <entry><literal>pg_catalog</></entry>
+ </row>
+
+ <row>
<entry><type>regconfig</></entry>
<entry><structname>pg_ts_config</></entry>
<entry>text search configuration</entry>
@@ -4474,9 +4481,9 @@ SELECT * FROM pg_attribute
<productname>PostgreSQL</productname> understands that the default
expression depends on the sequence <literal>my_seq</>; the system
will not let the sequence be dropped without first removing the
- default expression. <type>regrole</> is the exception for the
- property. Constants of this type are not allowed in such
- expressions.
+ default expression. <type>regrole</> and <type>regnamespace</> are
+ the exceptions for the property. Constants of these types are not
+ allowed in such expressions.
</para>
<note>
diff --git a/src/backend/bootstrap/bootstrap.c b/src/backend/bootstrap/bootstrap.c
index c375c96..f30d5e6 100644
--- a/src/backend/bootstrap/bootstrap.c
+++ b/src/backend/bootstrap/bootstrap.c
@@ -115,6 +115,8 @@ static const struct typinfo TypInfo[] = {
F_REGTYPEIN, F_REGTYPEOUT},
{"regrole", REGROLEOID, 0, 4, true, 'i', 'p', InvalidOid,
F_REGROLEIN, F_REGROLEOUT},
+ {"regnamespace", REGNAMESPACEOID, 0, 4, true, 'i', 'p', InvalidOid,
+ F_REGNAMESPACEIN, F_REGNAMESPACEOUT},
{"text", TEXTOID, 0, -1, false, 'i', 'x', DEFAULT_COLLATION_OID,
F_TEXTIN, F_TEXTOUT},
{"oid", OIDOID, 0, 4, true, 'i', 'p', InvalidOid,
diff --git a/src/backend/catalog/dependency.c b/src/backend/catalog/dependency.c
index c85f70a..a59c2cd 100644
--- a/src/backend/catalog/dependency.c
+++ b/src/backend/catalog/dependency.c
@@ -1599,11 +1599,12 @@ find_expr_references_walker(Node *node,
break;
/*
- * Dependencies for regrole in expressions are not handled as
- * same as other reg* types. So explicitly inhibit the usage
- * to get rid of confusions.
+ * Dependencies for regrole and regnamespace in expressions
+ * are not handled as same as other reg* types. So explicitly
+ * inhibit the usage to get rid of confusions.
*/
case REGROLEOID:
+ case REGNAMESPACEOID:
{
HeapTuple tt;
char *typename = "<unknown>";
diff --git a/src/backend/utils/adt/regproc.c b/src/backend/utils/adt/regproc.c
index a5196e7..d367e5e 100644
--- a/src/backend/utils/adt/regproc.c
+++ b/src/backend/utils/adt/regproc.c
@@ -1650,7 +1650,100 @@ regrolesend(PG_FUNCTION_ARGS)
return oidsend(fcinfo);
}
+/*
+ * regnamespacein - converts "nspname" to namespace OID
+ *
+ * We also accept a numeric OID, for symmetry with the output routine.
+ *
+ * '-' signifies unknown (OID 0). In all other cases, the input must
+ * match an existing pg_namespace entry.
+ */
+Datum
+regnamespacein(PG_FUNCTION_ARGS)
+{
+ char *nsp_name_or_oid = PG_GETARG_CSTRING(0);
+ Oid result = InvalidOid;
+
+ /* '-' ? */
+ if (strcmp(nsp_name_or_oid, "-") == 0)
+ PG_RETURN_OID(InvalidOid);
+
+ /* Numeric OID? */
+ if (nsp_name_or_oid[0] >= '0' &&
+ nsp_name_or_oid[0] <= '9' &&
+ strspn(nsp_name_or_oid, "0123456789") == strlen(nsp_name_or_oid))
+ {
+ result = DatumGetObjectId(DirectFunctionCall1(oidin,
+ CStringGetDatum(nsp_name_or_oid)));
+ PG_RETURN_OID(result);
+ }
+
+ /* Normal case: see if the name matches any pg_namespace entry. */
+ result = get_namespace_oid(nsp_name_or_oid, false);
+
+ PG_RETURN_OID(result);
+}
+
+/*
+ * to_regnamespace - converts "nspname" to namespace OID
+ *
+ * If the name is not found, we return NULL.
+ */
+Datum
+to_regnamespace(PG_FUNCTION_ARGS)
+{
+ char *nsp_name = PG_GETARG_CSTRING(0);
+ Oid result;
+
+ result = get_namespace_oid(nsp_name, true);
+
+ if (OidIsValid(result))
+ PG_RETURN_OID(result);
+ else
+ PG_RETURN_NULL();
+}
+
+/*
+ * regnamespaceout - converts namespace OID to "nsp_name"
+ */
+Datum
+regnamespaceout(PG_FUNCTION_ARGS)
+{
+ Oid nspid = PG_GETARG_OID(0);
+ char *result;
+
+ if (nspid == InvalidOid)
+ {
+ result = pstrdup("-");
+ PG_RETURN_CSTRING(result);
+ }
+
+ result = get_namespace_name(nspid);
+ if (result)
+ PG_RETURN_CSTRING(result);
+ else
+ PG_RETURN_NULL();
+}
+/*
+ * regnamespacerecv - converts external binary format to regnamespace
+ */
+Datum
+regnamespacerecv(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidrecv, so share code */
+ return oidrecv(fcinfo);
+}
+
+/*
+ * regnamespacesend - converts regnamespace to binary format
+ */
+Datum
+regnamespacesend(PG_FUNCTION_ARGS)
+{
+ /* Exactly the same as oidsend, so share code */
+ return oidsend(fcinfo);
+}
/*
* text_regclass: convert text to regclass
diff --git a/src/backend/utils/adt/selfuncs.c b/src/backend/utils/adt/selfuncs.c
index a28868c..91399f7 100644
--- a/src/backend/utils/adt/selfuncs.c
+++ b/src/backend/utils/adt/selfuncs.c
@@ -3620,6 +3620,7 @@ convert_to_scalar(Datum value, Oid valuetypid, double *scaledvalue,
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
*scaledvalue = convert_numeric_to_scalar(value, valuetypid);
*scaledlobound = convert_numeric_to_scalar(lobound, boundstypid);
*scaledhibound = convert_numeric_to_scalar(hibound, boundstypid);
@@ -3726,6 +3727,7 @@ convert_numeric_to_scalar(Datum value, Oid typid)
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
/* we can treat OIDs as integers... */
return (double) DatumGetObjectId(value);
}
diff --git a/src/backend/utils/cache/catcache.c b/src/backend/utils/cache/catcache.c
index 9b7cc5e..5bb03dd 100644
--- a/src/backend/utils/cache/catcache.c
+++ b/src/backend/utils/cache/catcache.c
@@ -151,6 +151,7 @@ GetCCHashEqFuncs(Oid keytype, PGFunction *hashfunc, RegProcedure *eqfunc)
case REGCONFIGOID:
case REGDICTIONARYOID:
case REGROLEOID:
+ case REGNAMESPACEOID:
*hashfunc = hashoid;
*eqfunc = F_OIDEQ;
diff --git a/src/include/catalog/pg_cast.h b/src/include/catalog/pg_cast.h
index 9e8cb1c..d1e303f 100644
--- a/src/include/catalog/pg_cast.h
+++ b/src/include/catalog/pg_cast.h
@@ -217,6 +217,13 @@ DATA(insert ( 21 4096 313 i f ));
DATA(insert ( 23 4096 0 i b ));
DATA(insert ( 4096 20 1288 a f ));
DATA(insert ( 4096 23 0 a b ));
+DATA(insert ( 26 4089 0 i b ));
+DATA(insert ( 4089 26 0 i b ));
+DATA(insert ( 20 4089 1287 i f ));
+DATA(insert ( 21 4089 313 i f ));
+DATA(insert ( 23 4089 0 i b ));
+DATA(insert ( 4089 20 1288 a f ));
+DATA(insert ( 4089 23 0 a b ));
/*
* String category
diff --git a/src/include/catalog/pg_proc.h b/src/include/catalog/pg_proc.h
index 7cdf8c2..e0cd476 100644
--- a/src/include/catalog/pg_proc.h
+++ b/src/include/catalog/pg_proc.h
@@ -3448,6 +3448,12 @@ DATA(insert OID = 4092 ( regroleout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2
DESCR("I/O");
DATA(insert OID = 4093 ( to_regrole PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4096 "2275" _null_ _null_ _null_ _null_ to_regrole _null_ _null_ _null_ ));
DESCR("convert role name to regrole");
+DATA(insert OID = 4084 ( regnamespacein PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ regnamespacein _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4085 ( regnamespaceout PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2275 "4089" _null_ _null_ _null_ _null_ regnamespaceout _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4086 ( to_regnamespace PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 4089 "2275" _null_ _null_ _null_ _null_ to_regnamespace _null_ _null_ _null_ ));
+DESCR("convert namespace name to regnamespace");
DATA(insert OID = 2246 ( fmgr_internal_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_internal_validator _null_ _null_ _null_ ));
DESCR("(internal)");
DATA(insert OID = 2247 ( fmgr_c_validator PGNSP PGUID 12 1 0 0 0 f f f f t f s 1 0 2278 "26" _null_ _null_ _null_ _null_ fmgr_c_validator _null_ _null_ _null_ ));
@@ -3847,6 +3853,10 @@ DATA(insert OID = 4094 ( regrolerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i
DESCR("I/O");
DATA(insert OID = 4095 ( regrolesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4096" _null_ _null_ _null_ _null_ regrolesend _null_ _null_ _null_ ));
DESCR("I/O");
+DATA(insert OID = 4087 ( regnamespacerecv PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 4089 "2281" _null_ _null_ _null_ _null_ regnamespacerecv _null_ _null_ _null_ ));
+DESCR("I/O");
+DATA(insert OID = 4088 ( regnamespacesend PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "4089" _null_ _null_ _null_ _null_ regnamespacesend _null_ _null_ _null_ ));
+DESCR("I/O");
DATA(insert OID = 2456 ( bit_recv PGNSP PGUID 12 1 0 0 0 f f f f t f i 3 0 1560 "2281 26 23" _null_ _null_ _null_ _null_ bit_recv _null_ _null_ _null_ ));
DESCR("I/O");
DATA(insert OID = 2457 ( bit_send PGNSP PGUID 12 1 0 0 0 f f f f t f i 1 0 17 "1560" _null_ _null_ _null_ _null_ bit_send _null_ _null_ _null_ ));
diff --git a/src/include/catalog/pg_type.h b/src/include/catalog/pg_type.h
index 1430bc1..2493353 100644
--- a/src/include/catalog/pg_type.h
+++ b/src/include/catalog/pg_type.h
@@ -568,6 +568,10 @@ DATA(insert OID = 4096 ( regrole PGNSP PGUID 4 t b N f t \054 0 0 4097 re
DESCR("registered role");
#define REGROLEOID 4096
+DATA(insert OID = 4089 ( regnamespace PGNSP PGUID 4 t b N f t \054 0 0 4090 regnamespacein regnamespaceout regnamespacerecv regnamespacesend - - - i p f 0 -1 0 0 _null_ _null_ _null_ ));
+DESCR("registered namespace");
+#define REGNAMESPACEOID 4089
+
DATA(insert OID = 2207 ( _regprocedure PGNSP PGUID -1 f b A f t \054 0 2202 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2208 ( _regoper PGNSP PGUID -1 f b A f t \054 0 2203 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
DATA(insert OID = 2209 ( _regoperator PGNSP PGUID -1 f b A f t \054 0 2204 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
@@ -575,6 +579,7 @@ DATA(insert OID = 2210 ( _regclass PGNSP PGUID -1 f b A f t \054 0 2205 0 arr
DATA(insert OID = 2211 ( _regtype PGNSP PGUID -1 f b A f t \054 0 2206 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
#define REGTYPEARRAYOID 2211
DATA(insert OID = 4097 ( _regrole PGNSP PGUID -1 f b A f t \054 0 4096 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
+DATA(insert OID = 4090 ( _regnamespace PGNSP PGUID -1 f b A f t \054 0 4089 0 array_in array_out array_recv array_send - - array_typanalyze i x f 0 -1 0 0 _null_ _null_ _null_ ));
/* uuid */
DATA(insert OID = 2950 ( uuid PGNSP PGUID 16 f b U f t \054 0 0 2951 uuid_in uuid_out uuid_recv uuid_send - - - c p f 0 -1 0 0 _null_ _null_ _null_ ));
diff --git a/src/include/utils/builtins.h b/src/include/utils/builtins.h
index 0e1e99e..7b3c162 100644
--- a/src/include/utils/builtins.h
+++ b/src/include/utils/builtins.h
@@ -635,6 +635,11 @@ extern Datum regroleout(PG_FUNCTION_ARGS);
extern Datum regrolerecv(PG_FUNCTION_ARGS);
extern Datum regrolesend(PG_FUNCTION_ARGS);
extern Datum to_regrole(PG_FUNCTION_ARGS);
+extern Datum regnamespacein(PG_FUNCTION_ARGS);
+extern Datum regnamespaceout(PG_FUNCTION_ARGS);
+extern Datum regnamespacerecv(PG_FUNCTION_ARGS);
+extern Datum regnamespacesend(PG_FUNCTION_ARGS);
+extern Datum to_regnamespace(PG_FUNCTION_ARGS);
extern Datum regconfigin(PG_FUNCTION_ARGS);
extern Datum regconfigout(PG_FUNCTION_ARGS);
extern Datum regconfigrecv(PG_FUNCTION_ARGS);
diff --git a/src/test/regress/expected/regproc.out b/src/test/regress/expected/regproc.out
index beda8ec..8c734f4 100644
--- a/src/test/regress/expected/regproc.out
+++ b/src/test/regress/expected/regproc.out
@@ -46,6 +46,12 @@ SELECT regrole('regtestrole');
regtestrole
(1 row)
+SELECT regnamespace('pg_catalog');
+ regnamespace
+--------------
+ pg_catalog
+(1 row)
+
SELECT to_regoper('||/');
to_regoper
------------
@@ -88,6 +94,12 @@ SELECT to_regrole('regtestrole');
regtestrole
(1 row)
+SELECT to_regnamespace('pg_catalog');
+ to_regnamespace
+-----------------
+ pg_catalog
+(1 row)
+
-- with schemaname
SELECT regoper('pg_catalog.||/');
regoper
@@ -186,6 +198,10 @@ SELECT regrole('regtestrole');
ERROR: role "regtestrole" does not exist
LINE 1: SELECT regrole('regtestrole');
^
+SELECT regnamespace('nonexistent');
+ERROR: schema "nonexistent" does not exist
+LINE 1: SELECT regnamespace('nonexistent');
+ ^
-- with schemaname
SELECT regoper('ng_catalog.||/');
ERROR: schema "ng_catalog" does not exist
@@ -255,6 +271,12 @@ SELECT to_regrole('regtestrole');
(1 row)
+SELECT to_regnamespace('nonexistent');
+ to_regnamespace
+-----------------
+
+(1 row)
+
-- with schemaname
SELECT to_regoper('ng_catalog.||/');
to_regoper
diff --git a/src/test/regress/sql/regproc.sql b/src/test/regress/sql/regproc.sql
index bc77c67..8edaf15 100644
--- a/src/test/regress/sql/regproc.sql
+++ b/src/test/regress/sql/regproc.sql
@@ -14,6 +14,7 @@ SELECT regprocedure('abs(numeric)');
SELECT regclass('pg_class');
SELECT regtype('int4');
SELECT regrole('regtestrole');
+SELECT regnamespace('pg_catalog');
SELECT to_regoper('||/');
SELECT to_regoperator('+(int4,int4)');
@@ -22,6 +23,7 @@ SELECT to_regprocedure('abs(numeric)');
SELECT to_regclass('pg_class');
SELECT to_regtype('int4');
SELECT to_regrole('regtestrole');
+SELECT to_regnamespace('pg_catalog');
-- with schemaname
@@ -51,6 +53,7 @@ SELECT regprocedure('absinthe(numeric)');
SELECT regclass('pg_classes');
SELECT regtype('int3');
SELECT regrole('regtestrole');
+SELECT regnamespace('nonexistent');
-- with schemaname
@@ -72,6 +75,7 @@ SELECT to_regprocedure('absinthe(numeric)');
SELECT to_regclass('pg_classes');
SELECT to_regtype('int3');
SELECT to_regrole('regtestrole');
+SELECT to_regnamespace('nonexistent');
-- with schemaname
--
2.1.0.GIT
The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passed
Looks good. Passing it to committer.
The new status of this patch is: Ready for Committer
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello, Thank you for reviewing, and sorry to have overlooked
this.
# I hope the CF app to add the author as a receiver when issueing
# a mail.
regards,
At Thu, 12 Mar 2015 11:06:29 +0000, Jeevan Chalke <jeevan.chalke@gmail.com> wrote in <20150312110629.2540.70807.pgcf@coridan.postgresql.org>
The following review has been posted through the commitfest application:
make installcheck-world: tested, passed
Implements feature: tested, passed
Spec compliant: tested, passed
Documentation: tested, passedLooks good. Passing it to committer.
The new status of this patch is: Ready for Committer
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Kyotaro HORIGUCHI wrote:
# I hope the CF app to add the author as a receiver when issueing
# a mail.
Moreover, it should add everyone who was in To, From, CC in the email
that the commitfest app is replying to; if the patch authors are not
listed, add them as well.
--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
At Thu, 19 Mar 2015 11:17:34 -0300, Alvaro Herrera <alvherre@2ndquadrant.com> wrote in <20150319141734.GE3636@alvh.no-ip.org>
Kyotaro HORIGUCHI wrote:
# I hope the CF app to add the author as a receiver when issueing
# a mail.Moreover, it should add everyone who was in To, From, CC in the email
that the commitfest app is replying to; if the patch authors are not
listed, add them as well.
It should do what ordinary mailers do for recipients list, as it
already does for References: and In-reply-to:.
--
Kyotaro Horiguchi
NTT Open Source Software Center
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 03/10/2015 04:42 AM, Kyotaro HORIGUCHI wrote:
Thank you for the correction.
At Wed, 4 Mar 2015 01:01:48 -0600, Jim Nasby <Jim.Nasby@BlueTreble.com> wrote in <54F6ADDC.8030201@BlueTreble.com>
On 3/3/15 8:04 PM, Kyotaro HORIGUCHI wrote:
Note: The OID alias types don't sctrictly comply the transaction
isolation rules so do not use them where exact transaction
isolation on the values of these types has a
significance. Likewise, since they look as simple constants to
planner so you might get slower plans than the queries joining
the system tables correnspond to the OID types.Might I suggest:
Note: The OID alias types do not completely follow transaction
isolation rules. The planner also treats them as simple constants,
which may result in sub-optimal planning.Looks far simple and enough.
The note has been replaced with your sentence in the attached patch.
I have just claimed this as committer in the CF, but on reviewing the
emails it looks like there is disagreement about the need for it at all,
especially from Tom and Robert.
I confess I have often wanted regnamespace, particularly, and
occasionally regrole, simply as a convenience. But I'm not going to
commit it against substantial opposition.
Do we need a vote?
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Andrew Dunstan <andrew@dunslane.net> writes:
I have just claimed this as committer in the CF, but on reviewing the
emails it looks like there is disagreement about the need for it at all,
especially from Tom and Robert.
I confess I have often wanted regnamespace, particularly, and
occasionally regrole, simply as a convenience. But I'm not going to
commit it against substantial opposition.
Do we need a vote?
My concern about it is basically that I don't see where we stop.
The existing regFOO alias types are provided for object classes which
have nontrivial naming conventions (schema qualification, overloaded
argument types, etc), so that you can't just do "select ... from
catalog where objectname = 'blah'". That doesn't apply to namespaces
or roles. So I'm afraid that once this precedent is established,
there will be demands for regFOO for every object class we have,
and I don't want that much clutter.
It may be that these two cases are so much more useful than any other
conceivable cases that we can do them and stop, but I don't think that
argument has been made convincingly.
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 3/29/15 1:55 PM, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I have just claimed this as committer in the CF, but on reviewing the
emails it looks like there is disagreement about the need for it at all,
especially from Tom and Robert.I confess I have often wanted regnamespace, particularly, and
occasionally regrole, simply as a convenience. But I'm not going to
commit it against substantial opposition.Do we need a vote?
My concern about it is basically that I don't see where we stop.
The existing regFOO alias types are provided for object classes which
have nontrivial naming conventions (schema qualification, overloaded
argument types, etc), so that you can't just do "select ... from
catalog where objectname = 'blah'". That doesn't apply to namespaces
or roles. So I'm afraid that once this precedent is established,
there will be demands for regFOO for every object class we have,
and I don't want that much clutter.
IMHO the real issue here is it's just a royal PITA to query the catalogs
in so many cases, especially on an ad-hoc basis. information_schema
helps in many cases, but it sometimes doesn't have PG-specific stuff
that you need. And if you're writing code you can't depend on it
actually being there. (I've also heard it's horribly slow...)
I don't see a good way to really solve that other than reviving
pg_sysview and pulling that in.
BTW, it would arguably be better if we just exposed the function that
deals with quoting and schemas; IIRC it doesn't actually need the catalog.
It may be that these two cases are so much more useful than any other
conceivable cases that we can do them and stop, but I don't think that
argument has been made convincingly.
Short of fixing the underlying problem I think regnamspace would
absolutely be worth it. I find myself wanting that all the time.
I generally don't care about roles too much, but maybe that's just me.
FWIW, (and off-topic...) the other thing I find very painful is dealing
with ACLs. has_*_privilege does what it does well, but if you want to do
anything else (such as ensure permissions on an object are specified as
you expect) you're stuck resorting to things like
NOT EXISTS( SELECT has_*_privilege() FROM pg_roles WHERE rolname NOT IN() )
which is awkward because you actually need one of those for every
permission you want to check.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
On 03/29/2015 02:55 PM, Tom Lane wrote:
Andrew Dunstan <andrew@dunslane.net> writes:
I have just claimed this as committer in the CF, but on reviewing the
emails it looks like there is disagreement about the need for it at all,
especially from Tom and Robert.
I confess I have often wanted regnamespace, particularly, and
occasionally regrole, simply as a convenience. But I'm not going to
commit it against substantial opposition.
Do we need a vote?My concern about it is basically that I don't see where we stop.
The existing regFOO alias types are provided for object classes which
have nontrivial naming conventions (schema qualification, overloaded
argument types, etc), so that you can't just do "select ... from
catalog where objectname = 'blah'". That doesn't apply to namespaces
or roles. So I'm afraid that once this precedent is established,
there will be demands for regFOO for every object class we have,
and I don't want that much clutter.It may be that these two cases are so much more useful than any other
conceivable cases that we can do them and stop, but I don't think that
argument has been made convincingly.
Well, here's a list of all the fooname attributes in the catalog, which
I guess are the prime candidates for regfoo pseudotypes. Besides those
we already have and the two proposed here, I'm not sure there will be
huge demand for others - tablespace maybe, trigger doesn't seem very
practicable, and I could just see suggestions for collation and
conversion, but those seem pretty marginal, and that seems to be about
it, to me.
attrelid | attname
--------------------------------------------+--------------------------
pg_proc | proname
pg_type | typname
pg_attribute | attname
pg_class | relname
pg_constraint | conname
pg_operator | oprname
pg_opfamily | opfname
pg_opclass | opcname
pg_am | amname
pg_language | lanname
pg_rewrite | rulename
pg_trigger | tgname
pg_event_trigger | evtname
pg_namespace | nspname
pg_conversion | conname
pg_database | datname
pg_tablespace | spcname
pg_pltemplate | tmplname
pg_authid | rolname
pg_ts_config | cfgname
pg_ts_dict | dictname
pg_ts_parser | prsname
pg_ts_template | tmplname
pg_extension | extname
pg_foreign_data_wrapper | fdwname
pg_foreign_server | srvname
pg_policy | polname
pg_collation | collname
cheers
andrew
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Andrew Dunstan <andrew@dunslane.net> writes:
On 03/29/2015 02:55 PM, Tom Lane wrote:
It may be that these two cases are so much more useful than any other
conceivable cases that we can do them and stop, but I don't think that
argument has been made convincingly.
Well, here's a list of all the fooname attributes in the catalog, which
I guess are the prime candidates for regfoo pseudotypes. Besides those
we already have and the two proposed here, I'm not sure there will be
huge demand for others - tablespace maybe, trigger doesn't seem very
practicable, and I could just see suggestions for collation and
conversion, but those seem pretty marginal, and that seems to be about
it, to me.
Hmm. We can ignore pg_attribute and pg_pltemplate, which don't have OIDs
and thus aren't candidates anyway. And we can ignore the ones
corresponding to the already-existing regFOO types. That leaves
pg_am | amname
pg_authid | rolname (*)
pg_collation | collname
pg_constraint | conname
pg_conversion | conname
pg_database | datname
pg_event_trigger | evtname
pg_extension | extname
pg_foreign_data_wrapper | fdwname
pg_foreign_server | srvname
pg_language | lanname
pg_namespace | nspname (*)
pg_opclass | opcname
pg_opfamily | opfname
pg_policy | polname
pg_rewrite | rulename
pg_tablespace | spcname
pg_trigger | tgname
pg_ts_parser | prsname
pg_ts_template | tmplname
of which the proposed patch covers the two starred ones.
OTOH, looking at this list, there are already numerous cases where
the object identity is more than just a name (eg, collations have
schema-qualified names, opfamilies are not only schema-qualified
but are per-index-AM as well, triggers and constraints are named
per-table, etc). So it's clear that we've already been applying
a "usefulness" criterion rather than just "does it have a
multi-component name" when choosing which objects to provide
regFOO types for.
In view of that, you could certainly argue that if someone's bothered
to make a patch to add a new regFOO type, it's useful enough. I don't
want to end up with thirtysomething of them, but we don't seem to be
trending in that direction.
Or in short, objection withdrawn. (As to the concept, anyway.
I've not read the patch...)
regards, tom lane
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
Hello,
At Tue, 31 Mar 2015 16:48:18 -0400, Tom Lane <tgl@sss.pgh.pa.us> wrote in <26969.1427834898@sss.pgh.pa.us>
Hmm. We can ignore pg_attribute and pg_pltemplate, which don't have OIDs
and thus aren't candidates anyway. And we can ignore the ones
corresponding to the already-existing regFOO types. That leavespg_am | amname
pg_authid | rolname (*)
pg_collation | collname
pg_constraint | conname
pg_conversion | conname
pg_database | datname
pg_event_trigger | evtname
pg_extension | extname
pg_foreign_data_wrapper | fdwname
pg_foreign_server | srvname
pg_language | lanname
pg_namespace | nspname (*)
pg_opclass | opcname
pg_opfamily | opfname
pg_policy | polname
pg_rewrite | rulename
pg_tablespace | spcname
pg_trigger | tgname
pg_ts_parser | prsname
pg_ts_template | tmplnameof which the proposed patch covers the two starred ones.
OTOH, looking at this list, there are already numerous cases where
the object identity is more than just a name (eg, collations have
schema-qualified names, opfamilies are not only schema-qualified
but are per-index-AM as well, triggers and constraints are named
per-table, etc). So it's clear that we've already been applying
a "usefulness" criterion rather than just "does it have a
multi-component name" when choosing which objects to provide
regFOO types for.
As I wrote before, the criteria I selected for choosing these
ones was how often the oid is referred to. The attached excel
file shows the complehensive list of reference counts.
Each cells is marked 'x' if the catalog of the row referrs to the
oid of the catalog on the column. So the numbers in the row 2
represents how mane times the oid of the catalog on the column is
referred to from other catalogs. Adding all catalog having tuple
oid and sorting by the number they are ordered as below.
(The upper cased 'X' in the HASOID column indicates that the view
exposes the oid of underlying table and identifying the rows in
the view)
(-) in the list below is the regFOO types already exists and the
second column is the number of other catalogs refers to the oid.
pg_authid | 33 | rolname (*)
+ pg_class | 27 | relname (-)
pg_namespace | 20 | nspname (*)
+ pg_type | 15 | typname (-)
+ pg_proc | 13 | proname (-)
+ pg_operator | 5 | oprname (-)
pg_database | 5 | datname
pg_am | 4 | amname
pg_collation | 4 | collname
pg_tablespace | 4 | spcname
pg_foreign_server | 3 | srvname
pg_opfamily | 3 | opfname
pg_opclass | 2 | opcname
pg_constraint | 1 | conname
pg_foreign_data_wrapper | 1 | fdwname
pg_language | 1 | lanname
+ pg_largeobject_metadata | 1 | -
pg_policy | 1 | polname
pg_rewrite | 1 | rulename
+ pg_ts_config | 1 | cfgname (-)
+ pg_ts_dict | 1 | dictname (-)
pg_ts_parser | 1 | prsname
pg_ts_template | 1 | tmplname
+ pg_user_mapping | 1 | -
+ pg_aggregate | 0 | -
All of amop, amproc, attrdef, cast, conversion, default_acl,
enum, event_trigger, extension, group, roles, shadow, trigger,
user are not referred to from any other catalogs.
In view of that, you could certainly argue that if someone's bothered
to make a patch to add a new regFOO type, it's useful enough. I don't
want to end up with thirtysomething of them, but we don't seem to be
trending in that direction.
pg_authid and pg_namespace are obviously win the race but haven't
got the prize. database to tablespace are in a gray zone but I
think they need highly significant reason to have regFOO type for
themselves.
On the other hand, regconfig(pg_ts_config) and
regdictionary(pg_ts_dist) have far less significance but I don't
assert they should be removed since they are there now.
Or in short, objection withdrawn. (As to the concept, anyway.
I've not read the patch...)
Thank you for your acceptance.
regards,
--
Kyotaro Horiguchi
NTT Open Source Software Center
Attachments:
pg_oid_refs.xlsxapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheetDownload
PK ! ���.� � �[Content_Types].xml ��(� �U�N�0�#����q)B�)�# �|����U��<Sh��IJ+@!��DY�6?���u��Hh�/�i>x���B<��"CR�(<b(�&�G��&f<�c!J�x)%�*�y����<�J?���J/��h8<�:xO�1�d|s�r�����V���"���WSB���V�B��7_Ha>�L����s� ���*��d�1M��������N�@�������Ib����������F��i� {S}���1��������O`�#�9��F�`���;�����!,�J���R��t���+��BD���- �F0������>�6n.`���-��6���s5��]��8�':���������%w��9�q�,U3%���.>bw���
�>��R�nY�9S&o �� PK ! �U0#� L �_rels/.rels ��(� ���N�0��H�C���nH���LH�!T�$����$@����Jc�����?[���iTb/N��(A�3b{�jx��V�b"gi��aW��l_x���b���������#b4O��r��0Q�ah���e���=��P-<��j{�>�<���4Mox/�}b�N�@�;�v�Cf�����B�I������"c�&�\O���8q"K��H��<��s@���.�h����<����Md�a��T_ �� PK ! ��; Y xl/_rels/workbook.xml.rels �(� ���J�0�����n�vu�t��W] ���l��L���7I-,�R���}�L2�����}���Y�C�l��Z�����yiJ�Z�$��W�Wl��H7=��bH�������NRb{4�RY�IBW�^�����i����3Mv(�C�v�������F��U��Yw"����t5z1E|�l�@�<���0J��I��L01��� �?A��oG�%���0��vM��a��]��3K/���
��6L^|�4�K��k��0�8��!�x|�!? �� PK ! ���&\ p xl/workbook.xml�R]O�0}7�?4}�m�6�F^���u�c
]������F|�_����v����|�u���&����Ro3��z��R�<��+�!�pt����;cw���h����fE����n`�8)�����n#�X��U �V��qTs���af��a�R�h����$�(�U�q4��R����M��k��W�(����DFGX�~4l�<�R�iOh���|�D@�[�W����b#���XK���P(�~#�0]����S5I)���F
_�x_z/ ����=K�@]����-}$�_�=x��C��D������.E~���3���^�1?�����%\�T��NX�#N�%� �� PK ! P�G� W xl/theme/theme1.xml�YMoE�#�F{om'vGu���h�F�[��x=��fvg53N�j$.HH�����q@@�V�~������;3���xM�����xg���c�_��(b��Iy��jW�"��G4Z��A�������3��7%�����[���
ID��r��P�d�R�>,cy�'$�wc."��Q���G�7b��ju�a{(���;S�����������f&��@J��^���k���2��AM#�Tv�@���<�5�G�Hy�a��E����W��^�)SKht=�I�R�����)�a.���7�m��
��E\���tk9?���Z]�<���Z;�Y ����;�F����Wtn���F3��25 ����_����V�Y|c_oou:k��,~m���\��x
��:��^�=��9�)��|����(��<���1���\��C.z �@����&d�}�����b- o\xc�|���e!�����n��*��^�|���zu�t�����������-/�p�A����������g_�|�i9^�?��O?~R�
�k�����<����~��I |K�a>���9B�<��c\��P\�bb�P�x�������bV�k�y�4�2���CG�~(&��H�Fp�s����������8(.&E�>��e�;8vB��$�5��t|� ��������B�? ����:~������z@Q�R���I�9�� .�2�!��ov��6geVo�C �Y���7����2����oc�)��
���J���;"R���`o!��0������i�"��e<oc���m~� q��a�4��w��(F{\��w�[!�������O����=8*�D��Kh�N��h�g��Q��6�4���[SYI��j��p�����'��\_�x���7}�����e�|�n;o��{��`�b3%GK��1e������fN��Y�z����!����$��iswp��� ���*��8���i&�LY%\���,���x���=6������.��U��
r6f� ��3���W����)��:�jZ�sK��L�s��&CM����0� �]��kpL���l�i��
8���e�H�xD�i�cT3A�r�\@���H����ZAZS��������qY��J���GI���rdq�8Y��Z^��������7�c-|�����f��J��?��M�����s��7��;} Rmc��0��`��d�_i�[/� ������:$�?���
-�����.�h�������"�����M�>���T{FT����������+�9�EW��28��Y�����*��M�:���z`[������bJ��L)�������u��HG���\�������
9t�$�~O��`zd\��kH*�S6�9��m�Y������i���H���=hK&��`VK�.����LF���U{H ����v������m��N����V�0�CN�����������3��a3�d��U,�U-�!����!��|��gU�
[A3-��T��[��X�42� ���b>%p�������1i�7������������<�n�vq��]���YY�����Z�Y_����=�l��y�}Ag���+����tv�a��vm��!��K���A����U���B������4�?+ �g����hH7� �� PK ! ;m2K� B # xl/worksheets/_rels/sheet1.xml.rels�����0E��Cx{���CS7"�U�b�������{�e���p��6��<�f�,����ch��{�-�A�8�� -<�a�.��NNJ���X��Q$��~���� ��>��I�y0������jm�_�/N��,�}W�:=RY���}<n���H���I9�`>�H9�E���bA�w��k}�m���� �� PK ! ��ZG# � xl/worksheets/sheet2.xml���N�0��H�C�;M�4@S� i����p�Z����Q�1x{�N����f��?������d��0+J�[���k�x��<�H�|��X�&X5�W���.D��S
�9,�L�A�RA}V4E�8���)DT���y[�w�)��HX�K��mqM����#$��8���
���Yu
�3�M5���xHb1^�%���sWC9�������(:�j?������e�bq���&{���
�<��i��z|Q��>�u�.�{�H�b�0�.@l���)3�:���2�����?�� �� PK ! ��ZG# � xl/worksheets/sheet3.xml���N�0��H�C�;M�4@S� i����p�Z����Q�1x{�N����f��?������d��0+J�[���k�x��<�H�|��X�&X5�W���.D��S
�9,�L�A�RA}V4E�8���)DT���y[�w�)��HX�K��mqM����#$��8���
���Yu
�3�M5���xHb1^�%���sWC9�������(:�j?������e�bq���&{���
�<��i��z|Q��>�u�.�{�H�b�0�.@l���)3�:���2�����?�� �� PK ! �`�� h xl/worksheets/sheet1.xml�]�r�H}�����v�6u�(��)Q���9q.3���t���JJ23_�h�8l�D��L}�F E�g�������n����y;8:i���������y�����vk�[>�.�O�y��t������:������O�]�4<m�����������>}\n����!w���rG��|;�>o��m&��p�99 ����v��ts������&M�7���]�d�>,w�{�z��/�nW��Z����=
NG���n���,���*��e�����u�����[�A�el��^�iN\�� )}^>�����V��v�wB����_��7������:o]�v���o��l�L����4N���f��/�H��]u�����[?�J��{&�>7���KEN�uz�+)���vv:v���^�+Q:$������t�4��M�6�[~�}X����7���Q��f�@g����� �v�q�W�����y��?
:4��t����Sn�o��_�2�U
:���3�����<�&#@��w�^q>�-�'�~�f��oy>9�P��B��V�50nP���B<89���RB������N~�d�o!�;��m�Z���F��*�����$��2��A�����o
yZ�K�!`*��aPF�9(4��,D�fKY�B`�!�p���`*#��S��9(W"j���2�A����
�2���BE���2�tl�i�'���]eJ3�FKQFd�Fd���)C�$��v��IsPh���2&;6&��[��9(�����-���>8\��.�&i�[��9(�o��2��A�a���e(um(�
�d��#sP0h���e��B���eum5��Wf5sP��p+�� 4��fu�W�9(4�����2�'��4�s�N<�[���L�����f��E�d���b��NI+u�ftd�
H]h6�-j����j���PgzS�3v��s�9�<gB��Y@���)8�X7���,����\pp�� |��.X���`��u$�����w��%W��Zs�S��j?p0����`�'�~�`��$@P���=p��k����]�0�SF&�+
��#�
,
�F���]�s"=52�_�`�H>���G�"��T�~��"��I�<��A{D�w� �:�#�z�#��h��C���C;�1e�*-�����rf��� p��s��9�:U.Mp`R\��e�q������6��C�Y� ��������G��tO'��9;�3��7U4�J����.��l�H\9�/�ydq�l���" ������doK�m,�n�,�Uc�,��F�t{,R`[�?����K|j,�������5������%F��"EZ�� ���J|zhABU��p-y� �Y��(r@vD��#��Q����"�G9 ?�� E��(r@�D�r$��$���#�:��G�p�AX��J�c� ���\��]�.`��j���"��/�JC�qt/�e
W�AN����%
�����3��w��tG����]y�G]S�j�d>����Pa;]��l���v�s���c��l�G�ss�NBd��������*�� ���P�����
W�!Rc��=#Q�����<s�����Pa��C���l���9V�]�h��c;����I��;s.�4\��^;�X�y��L�&�u�E�h���������:��s�n��c�*5Y�C������8�K���k$�B�����Vv�����M�&��p��w7�NBp08�8Jn�������x�.�>�������*�N���*��0�FL�� ������_�B���SatZ)
&�}�V�� ���B�������~����TA�.������pvlp �tB����)L�L���T+�V�
�?6�����00KHZ����]3?����TX���q�#�����E�i ��
|>�0�����#X�)L�f~x��� T��N��yl��`N 8!X�R+h�5��!�66�Fk0x0����s+
�<��z�����q�������bO���f�.�/UX������YEuD����D��1��,!����^E��������V��&���#P�2!X7*�tY�H����<yw�����ru�����S��x������ ~��Gt�c���y�F���^����y���M ~���|fH�fF��]s�V��[�� �D16�H���00KHZ_,���
tM��L����<�U������7� ��`� p���k���J�0��Y+���uX�����$��J��k`b}$�T�<�����L>�� ��<�T�N��]��0��� Z��NH���Z0]�Ji��A�g��A���<1�.�3[�7~��
K+��<i��B���Jn`%���
g08��
K+y���7y7h�������?Cc�:��I����'�?8O�a��S�y^����s��:�2!X_,8y��5Wai%oO��������y�U�2!X72�'�e��<y��y������:�1�v�b5|
�1UuI3x����-B.Lc� /3jkB��n0j� �Tai����v�gl�#���+��� �3�~x�����to�x��O���ah��k0���/u-$�TV�0�<]]�d`f���(>{��� �S�;�`���_��/��k?|�����=�.�� >k�g�+;\(��}�K��^]3`S�����Ra�B��p�����C�>J�JHZ�Bh �0�����*,���F����=l�Z��$���v����D��������X��N����=]5ws"�F��*-�Tz��n�!�X�5w�� �����_�T���J����Q�=�c-�F�e��<��������X��
Z�)��<��u����5������T\�� I�AU�^]3`N�����������2Wv��z����m�X�5&�>����.p������UX8�/�2�3nk��h};�;��%��N�<����#��[����s��Xc���y�H��fLT]��03x�_k����{0DlB��fLA�u�4Ct��A�m����9Z3#!X� �c�,�l������J��0+yW��x����\B�n%���.k��)��7}+\�G�����K]0�L����`f����9�0��A� �DD�����]�9Z#2��I}��tYwK3D������u;�s�����Bl� �Tai�R���L����@f��4�{���g�TR3^U�>VR��y|x� ]O����V���
�� �:Oe��J-4��a�9�@D|�N#�T�����
��S�"f�5���c�+����@D|�%c�W#��<
y�m|������h<xI`<x��"�u�xAE��HR=Pl��S~�}l��Us��e|�<�3��bF9��Q����g���7[��AC���n�����/�W�5�<k3�<i���C�:�:�v�j���������&��,�:�[{�u�tCL��:x8��<�2<���su�p��=<x�e<x����3�������O�������:x=�����;��_��t�W������;���2�q�����{xP��������:��;����3�������S�q��Q��y����gc^T��;��a�O����|����<0�
������%��4{:-oQ��%� U�"/H�O������F��� ������������S���yAJ�xJ�Dx��0�)�����TN�'�����yAR�xR�DxV�0�)�d��gUN�'����bD N��/xw� ~��"F<)s3xV�0+)f� ��v�H"<+s"<-G��#�:6�/-��'��9��3?�V����$0'�����ce�@k7>� �] ��bAj����JE��aEh}- �y*A5T*�����"P�T��RQ�xEG+�ca�p�3F��rSA�����a�T�!�W�Cs�@N��'��8a
S�f~��NP*����!L����`}�A�o����
�4C��C^i���X�53� ��`�J�j��5�����K/�&�T��u�2?�B��.��h_���AQ�O^����!G<%\[�4C�0�������F�J�������oL`*�9�u�S����/����?Tw�o��!����6�7�E� ��'�8�����@m��`�h4l�'��b�!�z� n���A��z8{�G�;cE3������� ��A���L��
�%c�l�����'���c�����f�2P%��&�>��U�� �pnx����������.z����w�]��_����tM��~ 5��^�r��7'��O�+��z7��&�����P��'�/�^ew��+��"�{z�nuC/4�[?���a���?/��o��o��m����B��zD5h���$;���d����/W)�wO��I����=m������;pF�u����z^>����?�fJ������������L�l��]�uO����C�l~i�^��6/�!�bhs�"���mF��z���� �� PK ! ��L
xl/sharedStrings.xml�WK��6��0|o<�EP�L�-�S�HN-��ZYR%zv7�>�ff�kzG��G��C����`��d���7�Ve�N���nS~����7e�\�;�������X�D�uiS�D���J���+����q ���U)D�&��4���j�k5�qe���hS���������{���������i]��uE�u5 �AJ|���R��`�$6���k�^
8���8�:�������B71�LKi+l4$����4���;a�]���K���3cL^�� A
I���U��rB"��93�%�J�� ���� K��E�q��E�u���0Wp������R�B���6 #3u
�I���.�Qt�q
>�a�EA��1r��-�}�/jQ�g*�f�)�y����/����{!w0`
�E>,6'o���>�0�8&X�!p?�[��d+�%N� ����MD*���&���r�D.���Q8�<�*Y/�"�s5�9�S� �����0�R�C��������Y��'�1�G�� ��'�3$�2UC���D�?��d����{�0��l�e�E�eesb��P*�]����f����yzLg���g�y��vt�o�E��������s.�\�5�\�w��������jpZ��T���Y7
���%7��a�KU:�\rt��&��Km"zg���ti���+?�u���;���0���L)��/�'�@\��lx ���x���,(N�"��&�(�Cd�9����y��,�����������3�\��X�������e����'\ax����kA�^������W����yE��`��/��|�F��=W�?�� �� PK ! ��34 9
xl/styles.xml�T���0��B���]�����
�B��-;�i���P��RZh�P�6���:�;�l���b�F�7��|��|�$Yq���)��(�:7��UJ���O�(q�t���<�
w�<{�(q�H~��Bh��@�"�\����Ss�;���.m��rV8I�(�N#���YR
��f�!�O;G���d�$��(Kr#�%��H��h�x8��~�o�����n�}������m��[%SB6�T��,�uH; �g��������zg�Yn�S����=�.�����U�#D�m���){��^5����p��� �=kj��F �����8]Y���gG�6`���-���:����%������Z�?��s`�`��L�nt��s)/��zW^�^�D/�T��"��@�,&&��/,��IQi�5��[�E9.yP��D��B���L���������c����z|��Z6S�����m�&�$Z[]��Q[�5�/>��$�W�>^��@��K!A�PN/��b�A"#�P`s�^<}TJ�K��0�7S:��y!��y��Xh!R:������������ �� PK ! �Q>�' � '