mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-02-05 19:09:58 +08:00
pg_dump: Refactor getIndexes()
Rearrange the version-dependent pieces in the new more modular style. Discussion: https://www.postgresql.org/message-id/flat/67a28a3f-7b79-a5a9-fcc7-947b170e66f0%40enterprisedb.com
This commit is contained in:
parent
222b697ec0
commit
e2c52beecd
@ -6508,6 +6508,50 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
|
|||||||
}
|
}
|
||||||
appendPQExpBufferChar(tbloids, '}');
|
appendPQExpBufferChar(tbloids, '}');
|
||||||
|
|
||||||
|
resetPQExpBuffer(query);
|
||||||
|
|
||||||
|
appendPQExpBuffer(query,
|
||||||
|
"SELECT t.tableoid, t.oid, i.indrelid, "
|
||||||
|
"t.relname AS indexname, "
|
||||||
|
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
|
||||||
|
"i.indkey, i.indisclustered, "
|
||||||
|
"c.contype, c.conname, "
|
||||||
|
"c.condeferrable, c.condeferred, "
|
||||||
|
"c.tableoid AS contableoid, "
|
||||||
|
"c.oid AS conoid, "
|
||||||
|
"pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
|
||||||
|
"(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
|
||||||
|
"t.reloptions AS indreloptions, ");
|
||||||
|
|
||||||
|
|
||||||
|
if (fout->remoteVersion >= 90400)
|
||||||
|
appendPQExpBuffer(query,
|
||||||
|
"i.indisreplident, ");
|
||||||
|
else
|
||||||
|
appendPQExpBuffer(query,
|
||||||
|
"false AS indisreplident, ");
|
||||||
|
|
||||||
|
if (fout->remoteVersion >= 110000)
|
||||||
|
appendPQExpBuffer(query,
|
||||||
|
"inh.inhparent AS parentidx, "
|
||||||
|
"i.indnkeyatts AS indnkeyatts, "
|
||||||
|
"i.indnatts AS indnatts, "
|
||||||
|
"(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
|
||||||
|
" FROM pg_catalog.pg_attribute "
|
||||||
|
" WHERE attrelid = i.indexrelid AND "
|
||||||
|
" attstattarget >= 0) AS indstatcols, "
|
||||||
|
"(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
|
||||||
|
" FROM pg_catalog.pg_attribute "
|
||||||
|
" WHERE attrelid = i.indexrelid AND "
|
||||||
|
" attstattarget >= 0) AS indstatvals ");
|
||||||
|
else
|
||||||
|
appendPQExpBuffer(query,
|
||||||
|
"0 AS parentidx, "
|
||||||
|
"i.indnatts AS indnkeyatts, "
|
||||||
|
"i.indnatts AS indnatts, "
|
||||||
|
"'' AS indstatcols, "
|
||||||
|
"'' AS indstatvals ");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The point of the messy-looking outer join is to find a constraint that
|
* The point of the messy-looking outer join is to find a constraint that
|
||||||
* is related by an internal dependency link to the index. If we find one,
|
* is related by an internal dependency link to the index. If we find one,
|
||||||
@ -6520,29 +6564,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
|
|||||||
if (fout->remoteVersion >= 110000)
|
if (fout->remoteVersion >= 110000)
|
||||||
{
|
{
|
||||||
appendPQExpBuffer(query,
|
appendPQExpBuffer(query,
|
||||||
"SELECT t.tableoid, t.oid, i.indrelid, "
|
|
||||||
"t.relname AS indexname, "
|
|
||||||
"inh.inhparent AS parentidx, "
|
|
||||||
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
|
|
||||||
"i.indnkeyatts AS indnkeyatts, "
|
|
||||||
"i.indnatts AS indnatts, "
|
|
||||||
"i.indkey, i.indisclustered, "
|
|
||||||
"i.indisreplident, "
|
|
||||||
"c.contype, c.conname, "
|
|
||||||
"c.condeferrable, c.condeferred, "
|
|
||||||
"c.tableoid AS contableoid, "
|
|
||||||
"c.oid AS conoid, "
|
|
||||||
"pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
|
|
||||||
"(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
|
|
||||||
"t.reloptions AS indreloptions, "
|
|
||||||
"(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
|
|
||||||
" FROM pg_catalog.pg_attribute "
|
|
||||||
" WHERE attrelid = i.indexrelid AND "
|
|
||||||
" attstattarget >= 0) AS indstatcols,"
|
|
||||||
"(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
|
|
||||||
" FROM pg_catalog.pg_attribute "
|
|
||||||
" WHERE attrelid = i.indexrelid AND "
|
|
||||||
" attstattarget >= 0) AS indstatvals "
|
|
||||||
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
|
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
|
||||||
"JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
|
"JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
|
||||||
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
|
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
|
||||||
@ -6558,41 +6579,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
|
|||||||
"ORDER BY i.indrelid, indexname",
|
"ORDER BY i.indrelid, indexname",
|
||||||
tbloids->data);
|
tbloids->data);
|
||||||
}
|
}
|
||||||
else if (fout->remoteVersion >= 90400)
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
* the test on indisready is necessary in 9.2, and harmless in
|
|
||||||
* earlier/later versions
|
|
||||||
*/
|
|
||||||
appendPQExpBuffer(query,
|
|
||||||
"SELECT t.tableoid, t.oid, i.indrelid, "
|
|
||||||
"t.relname AS indexname, "
|
|
||||||
"0 AS parentidx, "
|
|
||||||
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
|
|
||||||
"i.indnatts AS indnkeyatts, "
|
|
||||||
"i.indnatts AS indnatts, "
|
|
||||||
"i.indkey, i.indisclustered, "
|
|
||||||
"i.indisreplident, "
|
|
||||||
"c.contype, c.conname, "
|
|
||||||
"c.condeferrable, c.condeferred, "
|
|
||||||
"c.tableoid AS contableoid, "
|
|
||||||
"c.oid AS conoid, "
|
|
||||||
"pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
|
|
||||||
"(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
|
|
||||||
"t.reloptions AS indreloptions, "
|
|
||||||
"'' AS indstatcols, "
|
|
||||||
"'' AS indstatvals "
|
|
||||||
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
|
|
||||||
"JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
|
|
||||||
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
|
|
||||||
"LEFT JOIN pg_catalog.pg_constraint c "
|
|
||||||
"ON (i.indrelid = c.conrelid AND "
|
|
||||||
"i.indexrelid = c.conindid AND "
|
|
||||||
"c.contype IN ('p','u','x')) "
|
|
||||||
"WHERE i.indisvalid AND i.indisready "
|
|
||||||
"ORDER BY i.indrelid, indexname",
|
|
||||||
tbloids->data);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
@ -6600,23 +6586,6 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
|
|||||||
* earlier/later versions
|
* earlier/later versions
|
||||||
*/
|
*/
|
||||||
appendPQExpBuffer(query,
|
appendPQExpBuffer(query,
|
||||||
"SELECT t.tableoid, t.oid, i.indrelid, "
|
|
||||||
"t.relname AS indexname, "
|
|
||||||
"0 AS parentidx, "
|
|
||||||
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
|
|
||||||
"i.indnatts AS indnkeyatts, "
|
|
||||||
"i.indnatts AS indnatts, "
|
|
||||||
"i.indkey, i.indisclustered, "
|
|
||||||
"false AS indisreplident, "
|
|
||||||
"c.contype, c.conname, "
|
|
||||||
"c.condeferrable, c.condeferred, "
|
|
||||||
"c.tableoid AS contableoid, "
|
|
||||||
"c.oid AS conoid, "
|
|
||||||
"pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
|
|
||||||
"(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
|
|
||||||
"t.reloptions AS indreloptions, "
|
|
||||||
"'' AS indstatcols, "
|
|
||||||
"'' AS indstatvals "
|
|
||||||
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
|
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
|
||||||
"JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
|
"JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
|
||||||
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
|
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
|
||||||
|
Loading…
Reference in New Issue
Block a user