Skip to content

Commit e2c52be

Browse files
committed
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
1 parent 222b697 commit e2c52be

File tree

1 file changed

+44
-75
lines changed

1 file changed

+44
-75
lines changed

src/bin/pg_dump/pg_dump.c

Lines changed: 44 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -6508,6 +6508,50 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
65086508
}
65096509
appendPQExpBufferChar(tbloids, '}');
65106510

6511+
resetPQExpBuffer(query);
6512+
6513+
appendPQExpBuffer(query,
6514+
"SELECT t.tableoid, t.oid, i.indrelid, "
6515+
"t.relname AS indexname, "
6516+
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6517+
"i.indkey, i.indisclustered, "
6518+
"c.contype, c.conname, "
6519+
"c.condeferrable, c.condeferred, "
6520+
"c.tableoid AS contableoid, "
6521+
"c.oid AS conoid, "
6522+
"pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6523+
"(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6524+
"t.reloptions AS indreloptions, ");
6525+
6526+
6527+
if (fout->remoteVersion >= 90400)
6528+
appendPQExpBuffer(query,
6529+
"i.indisreplident, ");
6530+
else
6531+
appendPQExpBuffer(query,
6532+
"false AS indisreplident, ");
6533+
6534+
if (fout->remoteVersion >= 110000)
6535+
appendPQExpBuffer(query,
6536+
"inh.inhparent AS parentidx, "
6537+
"i.indnkeyatts AS indnkeyatts, "
6538+
"i.indnatts AS indnatts, "
6539+
"(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
6540+
" FROM pg_catalog.pg_attribute "
6541+
" WHERE attrelid = i.indexrelid AND "
6542+
" attstattarget >= 0) AS indstatcols, "
6543+
"(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
6544+
" FROM pg_catalog.pg_attribute "
6545+
" WHERE attrelid = i.indexrelid AND "
6546+
" attstattarget >= 0) AS indstatvals ");
6547+
else
6548+
appendPQExpBuffer(query,
6549+
"0 AS parentidx, "
6550+
"i.indnatts AS indnkeyatts, "
6551+
"i.indnatts AS indnatts, "
6552+
"'' AS indstatcols, "
6553+
"'' AS indstatvals ");
6554+
65116555
/*
65126556
* The point of the messy-looking outer join is to find a constraint that
65136557
* 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)
65206564
if (fout->remoteVersion >= 110000)
65216565
{
65226566
appendPQExpBuffer(query,
6523-
"SELECT t.tableoid, t.oid, i.indrelid, "
6524-
"t.relname AS indexname, "
6525-
"inh.inhparent AS parentidx, "
6526-
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6527-
"i.indnkeyatts AS indnkeyatts, "
6528-
"i.indnatts AS indnatts, "
6529-
"i.indkey, i.indisclustered, "
6530-
"i.indisreplident, "
6531-
"c.contype, c.conname, "
6532-
"c.condeferrable, c.condeferred, "
6533-
"c.tableoid AS contableoid, "
6534-
"c.oid AS conoid, "
6535-
"pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6536-
"(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6537-
"t.reloptions AS indreloptions, "
6538-
"(SELECT pg_catalog.array_agg(attnum ORDER BY attnum) "
6539-
" FROM pg_catalog.pg_attribute "
6540-
" WHERE attrelid = i.indexrelid AND "
6541-
" attstattarget >= 0) AS indstatcols,"
6542-
"(SELECT pg_catalog.array_agg(attstattarget ORDER BY attnum) "
6543-
" FROM pg_catalog.pg_attribute "
6544-
" WHERE attrelid = i.indexrelid AND "
6545-
" attstattarget >= 0) AS indstatvals "
65466567
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
65476568
"JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
65486569
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
@@ -6558,65 +6579,13 @@ getIndexes(Archive *fout, TableInfo tblinfo[], int numTables)
65586579
"ORDER BY i.indrelid, indexname",
65596580
tbloids->data);
65606581
}
6561-
else if (fout->remoteVersion >= 90400)
6562-
{
6563-
/*
6564-
* the test on indisready is necessary in 9.2, and harmless in
6565-
* earlier/later versions
6566-
*/
6567-
appendPQExpBuffer(query,
6568-
"SELECT t.tableoid, t.oid, i.indrelid, "
6569-
"t.relname AS indexname, "
6570-
"0 AS parentidx, "
6571-
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6572-
"i.indnatts AS indnkeyatts, "
6573-
"i.indnatts AS indnatts, "
6574-
"i.indkey, i.indisclustered, "
6575-
"i.indisreplident, "
6576-
"c.contype, c.conname, "
6577-
"c.condeferrable, c.condeferred, "
6578-
"c.tableoid AS contableoid, "
6579-
"c.oid AS conoid, "
6580-
"pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6581-
"(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6582-
"t.reloptions AS indreloptions, "
6583-
"'' AS indstatcols, "
6584-
"'' AS indstatvals "
6585-
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
6586-
"JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
6587-
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "
6588-
"LEFT JOIN pg_catalog.pg_constraint c "
6589-
"ON (i.indrelid = c.conrelid AND "
6590-
"i.indexrelid = c.conindid AND "
6591-
"c.contype IN ('p','u','x')) "
6592-
"WHERE i.indisvalid AND i.indisready "
6593-
"ORDER BY i.indrelid, indexname",
6594-
tbloids->data);
6595-
}
65966582
else
65976583
{
65986584
/*
65996585
* the test on indisready is necessary in 9.2, and harmless in
66006586
* earlier/later versions
66016587
*/
66026588
appendPQExpBuffer(query,
6603-
"SELECT t.tableoid, t.oid, i.indrelid, "
6604-
"t.relname AS indexname, "
6605-
"0 AS parentidx, "
6606-
"pg_catalog.pg_get_indexdef(i.indexrelid) AS indexdef, "
6607-
"i.indnatts AS indnkeyatts, "
6608-
"i.indnatts AS indnatts, "
6609-
"i.indkey, i.indisclustered, "
6610-
"false AS indisreplident, "
6611-
"c.contype, c.conname, "
6612-
"c.condeferrable, c.condeferred, "
6613-
"c.tableoid AS contableoid, "
6614-
"c.oid AS conoid, "
6615-
"pg_catalog.pg_get_constraintdef(c.oid, false) AS condef, "
6616-
"(SELECT spcname FROM pg_catalog.pg_tablespace s WHERE s.oid = t.reltablespace) AS tablespace, "
6617-
"t.reloptions AS indreloptions, "
6618-
"'' AS indstatcols, "
6619-
"'' AS indstatvals "
66206589
"FROM unnest('%s'::pg_catalog.oid[]) AS src(tbloid)\n"
66216590
"JOIN pg_catalog.pg_index i ON (src.tbloid = i.indrelid) "
66226591
"JOIN pg_catalog.pg_class t ON (t.oid = i.indexrelid) "

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy