1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-25 21:42:33 +03:00

Fix bug in dumping prior releases due to MV REFRESH dependency checking.

Reports and suggested patches from Fujii Masao and Andrew Dunstan.

Andrew Dunstan
This commit is contained in:
Kevin Grittner 2013-03-13 20:20:32 -05:00
parent ed3ddf918b
commit a18b72adcd

View File

@ -1769,7 +1769,7 @@ makeTableDataInfo(TableInfo *tbinfo, bool oids)
static void static void
buildMatViewRefreshDependencies(Archive *fout) buildMatViewRefreshDependencies(Archive *fout)
{ {
PQExpBuffer query = createPQExpBuffer(); PQExpBuffer query;
PGresult *res; PGresult *res;
int ntups, int ntups,
i; i;
@ -1777,38 +1777,41 @@ buildMatViewRefreshDependencies(Archive *fout)
i_objid, i_objid,
i_refobjid; i_refobjid;
/* No Mat Views before 9.3. */
if (fout->remoteVersion < 90300)
return;
/* Make sure we are in proper schema */ /* Make sure we are in proper schema */
selectSourceSchema(fout, "pg_catalog"); selectSourceSchema(fout, "pg_catalog");
if (fout->remoteVersion >= 90300) query = createPQExpBuffer();
{
appendPQExpBuffer(query, "with recursive w as " appendPQExpBuffer(query, "with recursive w as "
"( " "( "
"select d1.objid, d2.refobjid, c2.relkind as refrelkind " "select d1.objid, d2.refobjid, c2.relkind as refrelkind "
"from pg_depend d1 " "from pg_depend d1 "
"join pg_class c1 on c1.oid = d1.objid " "join pg_class c1 on c1.oid = d1.objid "
"and c1.relkind = 'm' " "and c1.relkind = 'm' "
"join pg_rewrite r1 on r1.ev_class = d1.objid " "join pg_rewrite r1 on r1.ev_class = d1.objid "
"join pg_depend d2 on d2.classid = 'pg_rewrite'::regclass " "join pg_depend d2 on d2.classid = 'pg_rewrite'::regclass "
"and d2.objid = r1.oid " "and d2.objid = r1.oid "
"and d2.refobjid <> d1.objid " "and d2.refobjid <> d1.objid "
"join pg_class c2 on c2.oid = d2.refobjid " "join pg_class c2 on c2.oid = d2.refobjid "
"and c2.relkind in ('m','v') " "and c2.relkind in ('m','v') "
"where d1.classid = 'pg_class'::regclass " "where d1.classid = 'pg_class'::regclass "
"union " "union "
"select w.objid, d3.refobjid, c3.relkind " "select w.objid, d3.refobjid, c3.relkind "
"from w " "from w "
"join pg_rewrite r3 on r3.ev_class = w.refobjid " "join pg_rewrite r3 on r3.ev_class = w.refobjid "
"join pg_depend d3 on d3.classid = 'pg_rewrite'::regclass " "join pg_depend d3 on d3.classid = 'pg_rewrite'::regclass "
"and d3.objid = r3.oid " "and d3.objid = r3.oid "
"and d3.refobjid <> w.refobjid " "and d3.refobjid <> w.refobjid "
"join pg_class c3 on c3.oid = d3.refobjid " "join pg_class c3 on c3.oid = d3.refobjid "
"and c3.relkind in ('m','v') " "and c3.relkind in ('m','v') "
") " ") "
"select 'pg_class'::regclass::oid as classid, objid, refobjid " "select 'pg_class'::regclass::oid as classid, objid, refobjid "
"from w " "from w "
"where refrelkind = 'm'"); "where refrelkind = 'm'");
}
res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK); res = ExecuteSqlQuery(fout, query->data, PGRES_TUPLES_OK);