mirror of
https://github.com/postgres/postgres.git
synced 2025-09-02 04:21:28 +03:00
Replace pg_class.reltriggers with relhastriggers, which is just a boolean hint
("there might be triggers") rather than an exact count. This is necessary catalog infrastructure for the upcoming patch to reduce the strength of locking needed for trigger addition/removal. Split out and committed separately for ease of reviewing/testing. In passing, also get rid of the unused pg_class columns relukeys, relfkeys, and relrefs, which haven't been maintained in many years and now have no chance of ever being maintained (because of wishing to avoid locking). Simon Riggs
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
* by PostgreSQL
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.504 2008/11/09 00:28:35 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_dump.c,v 1.505 2008/11/09 21:24:32 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -3070,7 +3070,7 @@ getTables(int *numTables)
|
||||
int i_relacl;
|
||||
int i_rolname;
|
||||
int i_relchecks;
|
||||
int i_reltriggers;
|
||||
int i_relhastriggers;
|
||||
int i_relhasindex;
|
||||
int i_relhasrules;
|
||||
int i_relhasoids;
|
||||
@@ -3102,7 +3102,7 @@ getTables(int *numTables)
|
||||
* we cannot correctly identify inherited columns, owned sequences, etc.
|
||||
*/
|
||||
|
||||
if (g_fout->remoteVersion >= 80200)
|
||||
if (g_fout->remoteVersion >= 80400)
|
||||
{
|
||||
/*
|
||||
* Left join to pick up dependency info linking sequences to their
|
||||
@@ -3112,7 +3112,36 @@ getTables(int *numTables)
|
||||
"SELECT c.tableoid, c.oid, relname, "
|
||||
"relacl, relkind, relnamespace, "
|
||||
"(%s relowner) as rolname, "
|
||||
"relchecks, reltriggers, "
|
||||
"relchecks, relhastriggers, "
|
||||
"relhasindex, relhasrules, relhasoids, "
|
||||
"d.refobjid as owning_tab, "
|
||||
"d.refobjsubid as owning_col, "
|
||||
"(SELECT spcname FROM pg_tablespace t WHERE t.oid = c.reltablespace) AS reltablespace, "
|
||||
"array_to_string(c.reloptions, ', ') as reloptions "
|
||||
"from pg_class c "
|
||||
"left join pg_depend d on "
|
||||
"(c.relkind = '%c' and "
|
||||
"d.classid = c.tableoid and d.objid = c.oid and "
|
||||
"d.objsubid = 0 and "
|
||||
"d.refclassid = c.tableoid and d.deptype = 'a') "
|
||||
"where relkind in ('%c', '%c', '%c', '%c') "
|
||||
"order by c.oid",
|
||||
username_subquery,
|
||||
RELKIND_SEQUENCE,
|
||||
RELKIND_RELATION, RELKIND_SEQUENCE,
|
||||
RELKIND_VIEW, RELKIND_COMPOSITE_TYPE);
|
||||
}
|
||||
else if (g_fout->remoteVersion >= 80200)
|
||||
{
|
||||
/*
|
||||
* Left join to pick up dependency info linking sequences to their
|
||||
* owning column, if any (note this dependency is AUTO as of 8.2)
|
||||
*/
|
||||
appendPQExpBuffer(query,
|
||||
"SELECT c.tableoid, c.oid, relname, "
|
||||
"relacl, relkind, relnamespace, "
|
||||
"(%s relowner) as rolname, "
|
||||
"relchecks, (reltriggers <> 0) as relhastriggers, "
|
||||
"relhasindex, relhasrules, relhasoids, "
|
||||
"d.refobjid as owning_tab, "
|
||||
"d.refobjsubid as owning_col, "
|
||||
@@ -3141,7 +3170,7 @@ getTables(int *numTables)
|
||||
"SELECT c.tableoid, c.oid, relname, "
|
||||
"relacl, relkind, relnamespace, "
|
||||
"(%s relowner) as rolname, "
|
||||
"relchecks, reltriggers, "
|
||||
"relchecks, (reltriggers <> 0) as relhastriggers, "
|
||||
"relhasindex, relhasrules, relhasoids, "
|
||||
"d.refobjid as owning_tab, "
|
||||
"d.refobjsubid as owning_col, "
|
||||
@@ -3170,7 +3199,7 @@ getTables(int *numTables)
|
||||
"SELECT c.tableoid, c.oid, relname, "
|
||||
"relacl, relkind, relnamespace, "
|
||||
"(%s relowner) as rolname, "
|
||||
"relchecks, reltriggers, "
|
||||
"relchecks, (reltriggers <> 0) as relhastriggers, "
|
||||
"relhasindex, relhasrules, relhasoids, "
|
||||
"d.refobjid as owning_tab, "
|
||||
"d.refobjsubid as owning_col, "
|
||||
@@ -3195,7 +3224,7 @@ getTables(int *numTables)
|
||||
"SELECT tableoid, oid, relname, relacl, relkind, "
|
||||
"0::oid as relnamespace, "
|
||||
"(%s relowner) as rolname, "
|
||||
"relchecks, reltriggers, "
|
||||
"relchecks, (reltriggers <> 0) as relhastriggers, "
|
||||
"relhasindex, relhasrules, relhasoids, "
|
||||
"NULL::oid as owning_tab, "
|
||||
"NULL::int4 as owning_col, "
|
||||
@@ -3214,7 +3243,7 @@ getTables(int *numTables)
|
||||
"SELECT tableoid, oid, relname, relacl, relkind, "
|
||||
"0::oid as relnamespace, "
|
||||
"(%s relowner) as rolname, "
|
||||
"relchecks, reltriggers, "
|
||||
"relchecks, (reltriggers <> 0) as relhastriggers, "
|
||||
"relhasindex, relhasrules, "
|
||||
"'t'::bool as relhasoids, "
|
||||
"NULL::oid as owning_tab, "
|
||||
@@ -3244,7 +3273,7 @@ getTables(int *numTables)
|
||||
"ELSE relkind END AS relkind,"
|
||||
"0::oid as relnamespace, "
|
||||
"(%s relowner) as rolname, "
|
||||
"relchecks, reltriggers, "
|
||||
"relchecks, (reltriggers <> 0) as relhastriggers, "
|
||||
"relhasindex, relhasrules, "
|
||||
"'t'::bool as relhasoids, "
|
||||
"NULL::oid as owning_tab, "
|
||||
@@ -3285,7 +3314,7 @@ getTables(int *numTables)
|
||||
i_relkind = PQfnumber(res, "relkind");
|
||||
i_rolname = PQfnumber(res, "rolname");
|
||||
i_relchecks = PQfnumber(res, "relchecks");
|
||||
i_reltriggers = PQfnumber(res, "reltriggers");
|
||||
i_relhastriggers = PQfnumber(res, "relhastriggers");
|
||||
i_relhasindex = PQfnumber(res, "relhasindex");
|
||||
i_relhasrules = PQfnumber(res, "relhasrules");
|
||||
i_relhasoids = PQfnumber(res, "relhasoids");
|
||||
@@ -3323,9 +3352,9 @@ getTables(int *numTables)
|
||||
tblinfo[i].relkind = *(PQgetvalue(res, i, i_relkind));
|
||||
tblinfo[i].hasindex = (strcmp(PQgetvalue(res, i, i_relhasindex), "t") == 0);
|
||||
tblinfo[i].hasrules = (strcmp(PQgetvalue(res, i, i_relhasrules), "t") == 0);
|
||||
tblinfo[i].hastriggers = (strcmp(PQgetvalue(res, i, i_relhastriggers), "t") == 0);
|
||||
tblinfo[i].hasoids = (strcmp(PQgetvalue(res, i, i_relhasoids), "t") == 0);
|
||||
tblinfo[i].ncheck = atoi(PQgetvalue(res, i, i_relchecks));
|
||||
tblinfo[i].ntrig = atoi(PQgetvalue(res, i, i_reltriggers));
|
||||
if (PQgetisnull(res, i, i_owning_tab))
|
||||
{
|
||||
tblinfo[i].owning_tab = InvalidOid;
|
||||
@@ -3779,7 +3808,7 @@ getConstraints(TableInfo tblinfo[], int numTables)
|
||||
{
|
||||
TableInfo *tbinfo = &tblinfo[i];
|
||||
|
||||
if (tbinfo->ntrig == 0 || !tbinfo->dobj.dump)
|
||||
if (!tbinfo->hastriggers || !tbinfo->dobj.dump)
|
||||
continue;
|
||||
|
||||
if (g_verbose)
|
||||
@@ -4090,7 +4119,7 @@ getTriggers(TableInfo tblinfo[], int numTables)
|
||||
{
|
||||
TableInfo *tbinfo = &tblinfo[i];
|
||||
|
||||
if (tbinfo->ntrig == 0 || !tbinfo->dobj.dump)
|
||||
if (!tbinfo->hastriggers || !tbinfo->dobj.dump)
|
||||
continue;
|
||||
|
||||
if (g_verbose)
|
||||
@@ -4177,16 +4206,6 @@ getTriggers(TableInfo tblinfo[], int numTables)
|
||||
|
||||
ntups = PQntuples(res);
|
||||
|
||||
/*
|
||||
* We may have less triggers than recorded due to having ignored
|
||||
* foreign-key triggers
|
||||
*/
|
||||
if (ntups > tbinfo->ntrig)
|
||||
{
|
||||
write_msg(NULL, "expected %d triggers on table \"%s\" but found %d\n",
|
||||
tbinfo->ntrig, tbinfo->dobj.name, ntups);
|
||||
exit_nicely();
|
||||
}
|
||||
i_tableoid = PQfnumber(res, "tableoid");
|
||||
i_oid = PQfnumber(res, "oid");
|
||||
i_tgname = PQfnumber(res, "tgname");
|
||||
|
Reference in New Issue
Block a user