Commit 15df0378 authored by Peter Eisentraut's avatar Peter Eisentraut

pg_dump: Dump operators with the same name ordered by arity

pg_dump sorts operators by name, but operators with the same name come
out in random order.  Now operators with the same name are dumped in
the order prefix, postfix, infix.  (This is consistent with functions,
which are dumped in increasing number of argument order.)
parent 104e7dac
...@@ -3138,6 +3138,7 @@ getOperators(int *numOprs) ...@@ -3138,6 +3138,7 @@ getOperators(int *numOprs)
int i_oprname; int i_oprname;
int i_oprnamespace; int i_oprnamespace;
int i_rolname; int i_rolname;
int i_oprkind;
int i_oprcode; int i_oprcode;
/* /*
...@@ -3153,6 +3154,7 @@ getOperators(int *numOprs) ...@@ -3153,6 +3154,7 @@ getOperators(int *numOprs)
appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
"oprnamespace, " "oprnamespace, "
"(%s oprowner) AS rolname, " "(%s oprowner) AS rolname, "
"oprkind, "
"oprcode::oid AS oprcode " "oprcode::oid AS oprcode "
"FROM pg_operator", "FROM pg_operator",
username_subquery); username_subquery);
...@@ -3162,6 +3164,7 @@ getOperators(int *numOprs) ...@@ -3162,6 +3164,7 @@ getOperators(int *numOprs)
appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, " appendPQExpBuffer(query, "SELECT tableoid, oid, oprname, "
"0::oid AS oprnamespace, " "0::oid AS oprnamespace, "
"(%s oprowner) AS rolname, " "(%s oprowner) AS rolname, "
"oprkind, "
"oprcode::oid AS oprcode " "oprcode::oid AS oprcode "
"FROM pg_operator", "FROM pg_operator",
username_subquery); username_subquery);
...@@ -3173,6 +3176,7 @@ getOperators(int *numOprs) ...@@ -3173,6 +3176,7 @@ getOperators(int *numOprs)
"oid, oprname, " "oid, oprname, "
"0::oid AS oprnamespace, " "0::oid AS oprnamespace, "
"(%s oprowner) AS rolname, " "(%s oprowner) AS rolname, "
"oprkind, "
"oprcode::oid AS oprcode " "oprcode::oid AS oprcode "
"FROM pg_operator", "FROM pg_operator",
username_subquery); username_subquery);
...@@ -3191,6 +3195,7 @@ getOperators(int *numOprs) ...@@ -3191,6 +3195,7 @@ getOperators(int *numOprs)
i_oprname = PQfnumber(res, "oprname"); i_oprname = PQfnumber(res, "oprname");
i_oprnamespace = PQfnumber(res, "oprnamespace"); i_oprnamespace = PQfnumber(res, "oprnamespace");
i_rolname = PQfnumber(res, "rolname"); i_rolname = PQfnumber(res, "rolname");
i_oprkind = PQfnumber(res, "oprkind");
i_oprcode = PQfnumber(res, "oprcode"); i_oprcode = PQfnumber(res, "oprcode");
for (i = 0; i < ntups; i++) for (i = 0; i < ntups; i++)
...@@ -3203,6 +3208,7 @@ getOperators(int *numOprs) ...@@ -3203,6 +3208,7 @@ getOperators(int *numOprs)
oprinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)), oprinfo[i].dobj.namespace = findNamespace(atooid(PQgetvalue(res, i, i_oprnamespace)),
oprinfo[i].dobj.catId.oid); oprinfo[i].dobj.catId.oid);
oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname)); oprinfo[i].rolname = pg_strdup(PQgetvalue(res, i, i_rolname));
oprinfo[i].oprkind = (PQgetvalue(res, i, i_oprkind))[0];
oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode)); oprinfo[i].oprcode = atooid(PQgetvalue(res, i, i_oprcode));
/* Decide whether we want to dump it */ /* Decide whether we want to dump it */
......
...@@ -204,6 +204,7 @@ typedef struct _oprInfo ...@@ -204,6 +204,7 @@ typedef struct _oprInfo
{ {
DumpableObject dobj; DumpableObject dobj;
char *rolname; char *rolname;
char oprkind;
Oid oprcode; Oid oprcode;
} OprInfo; } OprInfo;
......
...@@ -178,6 +178,16 @@ DOTypeNameCompare(const void *p1, const void *p2) ...@@ -178,6 +178,16 @@ DOTypeNameCompare(const void *p1, const void *p2)
if (cmpval != 0) if (cmpval != 0)
return cmpval; return cmpval;
} }
else if (obj1->objType == DO_OPERATOR)
{
OprInfo *oobj1 = *(OprInfo * const *) p1;
OprInfo *oobj2 = *(OprInfo * const *) p2;
/* oprkind is 'l', 'r', or 'b'; this sorts prefix, postfix, infix */
cmpval = (oobj2->oprkind - oobj1->oprkind);
if (cmpval != 0)
return cmpval;
}
/* Usually shouldn't get here, but if we do, sort by OID */ /* Usually shouldn't get here, but if we do, sort by OID */
return oidcmp(obj1->catId.oid, obj2->catId.oid); return oidcmp(obj1->catId.oid, obj2->catId.oid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment