2222 *
2323 *
2424 * IDENTIFICATION
25- * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.214 2001/07/16 05:06:59 tgl Exp $
25+ * $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.215 2001/07/17 00:30:35 tgl Exp $
2626 *
2727 * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828 *
@@ -1744,8 +1744,10 @@ clearIndInfo(IndInfo *ind, int numIndexes)
17441744return ;
17451745for (i = 0 ;i < numIndexes ;++ i )
17461746{
1747- if (ind [i ].indoid )
1748- free (ind [i ].indoid );
1747+ if (ind [i ].indexreloid )
1748+ free (ind [i ].indexreloid );
1749+ if (ind [i ].indreloid )
1750+ free (ind [i ].indreloid );
17491751if (ind [i ].indexrelname )
17501752free (ind [i ].indexrelname );
17511753if (ind [i ].indrelname )
@@ -1758,8 +1760,8 @@ clearIndInfo(IndInfo *ind, int numIndexes)
17581760free (ind [i ].indisunique );
17591761if (ind [i ].indisprimary )
17601762free (ind [i ].indisprimary );
1761- if (ind [i ].indpred )
1762- free (ind [i ].indpred );
1763+ if (ind [i ].indhaspred )
1764+ free (ind [i ].indhaspred );
17631765for (a = 0 ;a < INDEX_MAX_KEYS ;++ a )
17641766{
17651767if (ind [i ].indkey [a ])
@@ -2264,7 +2266,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
22642266
22652267resetPQExpBuffer (query );
22662268appendPQExpBuffer (query ,
2267- "SELECTOid FROM pg_index i WHERE i.indisprimary AND i.indrelid = %s " ,
2269+ "SELECTindexrelid FROM pg_index i WHERE i.indisprimary AND i.indrelid = %s " ,
22682270tblinfo [i ].oid );
22692271res2 = PQexec (g_conn ,query -> data );
22702272if (!res2 || PQresultStatus (res2 )!= PGRES_TUPLES_OK )
@@ -2297,31 +2299,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
22972299int n ;
22982300
22992301resetPQExpBuffer (query );
2300- if (g_fout -> remoteVersion < 70100 )
2301- {
2302- /* Fake the LOJ from below */
2303- appendPQExpBuffer (query ,
2304- " SELECT c.relname "
2305- " FROM pg_index i, pg_class c "
2306- " WHERE i.indrelid = %s"
2307- " AND i.indisprimary "
2308- " AND c.oid = i.indexrelid"
2309- " UNION ALL "
2310- " SELECT NULL "
2311- " FROM pg_index i "
2312- " WHERE i.indrelid = %s"
2313- " AND i.indisprimary "
2314- " And NOT Exists(Select * From pg_class c Where c.oid = i.indexrelid)" ,
2315- tblinfo [i ].oid ,tblinfo [i ].oid );
2316-
2317- }else {
2318- appendPQExpBuffer (query ,
2319- "SELECT c.relname "
2320- "FROM pg_index i LEFT OUTER JOIN pg_class c ON c.oid = i.indexrelid "
2321- "WHERE i.indrelid = %s"
2322- "AND i.indisprimary " ,
2323- tblinfo [i ].oid );
2324- }
2302+ appendPQExpBuffer (query ,
2303+ "SELECT relname FROM pg_class "
2304+ "WHERE oid = %s" ,
2305+ tblinfo [i ].pkIndexOid );
23252306
23262307res2 = PQexec (g_conn ,query -> data );
23272308if (!res2 || PQresultStatus (res2 )!= PGRES_TUPLES_OK )
@@ -2339,14 +2320,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
23392320exit_nicely ();
23402321}
23412322
2342- /* Sanity check on LOJ */
2343- if (PQgetisnull (res2 ,0 ,0 ))
2344- {
2345- write_msg (NULL ,"name of primary key of table \"%s\" returned NULL value\n" ,
2346- tblinfo [i ].relname );
2347- exit_nicely ();
2348- }
2349-
23502323tblinfo [i ].primary_key_name =
23512324strdup (fmtId (PQgetvalue (res2 ,0 ,0 ),force_quotes ));
23522325if (tblinfo [i ].primary_key_name == NULL )
@@ -2879,17 +2852,17 @@ getIndexes(int *numIndexes)
28792852int ntups ;
28802853IndInfo * indinfo ;
28812854
2855+ int i_indexreloid ;
2856+ int i_indreloid ;
28822857int i_indexrelname ;
28832858int i_indrelname ;
28842859int i_indamname ;
28852860int i_indproc ;
28862861int i_indkey ;
28872862int i_indclass ;
28882863int i_indisunique ;
2889- int i_indoid ;
2890- int i_oid ;
28912864int i_indisprimary ;
2892- int i_indpred ;
2865+ int i_indhaspred ;
28932866
28942867/*
28952868 * find all the user-defined indexes.
@@ -2902,11 +2875,14 @@ getIndexes(int *numIndexes)
29022875 */
29032876
29042877appendPQExpBuffer (query ,
2905- "SELECT i.oid, t1.oid as indoid, t1.relname as indexrelname, t2.relname as indrelname, "
2878+ "SELECT i.indexrelid as indexreloid, "
2879+ "i.indrelid as indreloid, "
2880+ "t1.relname as indexrelname, t2.relname as indrelname, "
29062881"i.indproc, i.indkey, i.indclass, "
2907- "a.amname as indamname, i.indisunique, i.indisprimary, i.indpred "
2908- "from pg_index i, pg_class t1, pg_class t2, pg_am a "
2909- "WHERE t1.oid = i.indexrelid and t2.oid = i.indrelid "
2882+ "a.amname as indamname, i.indisunique, i.indisprimary, "
2883+ "length(i.indpred) > 0 as indhaspred "
2884+ "from pg_index i, pg_class t1, pg_class t2, pg_am a "
2885+ "WHERE t1.oid = i.indexrelid and t2.oid = i.indrelid "
29102886"and t1.relam = a.oid and i.indexrelid > '%u'::oid "
29112887"and t2.relname !~ '^pg_' " ,
29122888g_last_builtin_oid );
@@ -2930,8 +2906,8 @@ getIndexes(int *numIndexes)
29302906
29312907memset ((char * )indinfo ,0 ,ntups * sizeof (IndInfo ));
29322908
2933- i_oid = PQfnumber (res ,"oid " );
2934- i_indoid = PQfnumber (res ,"indoid " );
2909+ i_indexreloid = PQfnumber (res ,"indexreloid " );
2910+ i_indreloid = PQfnumber (res ,"indreloid " );
29352911i_indexrelname = PQfnumber (res ,"indexrelname" );
29362912i_indrelname = PQfnumber (res ,"indrelname" );
29372913i_indamname = PQfnumber (res ,"indamname" );
@@ -2940,12 +2916,12 @@ getIndexes(int *numIndexes)
29402916i_indclass = PQfnumber (res ,"indclass" );
29412917i_indisunique = PQfnumber (res ,"indisunique" );
29422918i_indisprimary = PQfnumber (res ,"indisprimary" );
2943- i_indpred = PQfnumber (res ,"indpred " );
2919+ i_indhaspred = PQfnumber (res ,"indhaspred " );
29442920
29452921for (i = 0 ;i < ntups ;i ++ )
29462922{
2947- indinfo [i ].oid = strdup (PQgetvalue (res ,i ,i_oid ));
2948- indinfo [i ].indoid = strdup (PQgetvalue (res ,i ,i_indoid ));
2923+ indinfo [i ].indexreloid = strdup (PQgetvalue (res ,i ,i_indexreloid ));
2924+ indinfo [i ].indreloid = strdup (PQgetvalue (res ,i ,i_indreloid ));
29492925indinfo [i ].indexrelname = strdup (PQgetvalue (res ,i ,i_indexrelname ));
29502926indinfo [i ].indrelname = strdup (PQgetvalue (res ,i ,i_indrelname ));
29512927indinfo [i ].indamname = strdup (PQgetvalue (res ,i ,i_indamname ));
@@ -2958,7 +2934,7 @@ getIndexes(int *numIndexes)
29582934INDEX_MAX_KEYS );
29592935indinfo [i ].indisunique = strdup (PQgetvalue (res ,i ,i_indisunique ));
29602936indinfo [i ].indisprimary = strdup (PQgetvalue (res ,i ,i_indisprimary ));
2961- indinfo [i ].indpred = strdup (PQgetvalue (res ,i ,i_indpred ));
2937+ indinfo [i ].indhaspred = strdup (PQgetvalue (res ,i ,i_indhaspred ));
29622938}
29632939PQclear (res );
29642940return indinfo ;
@@ -4106,7 +4082,8 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
41064082/* Find the corresponding index */
41074083for (k = 0 ;k < numIndexes ;k ++ )
41084084{
4109- if (strcmp (indinfo [k ].oid ,tblinfo [i ].pkIndexOid )== 0 )
4085+ if (strcmp (indinfo [k ].indexreloid ,
4086+ tblinfo [i ].pkIndexOid )== 0 )
41104087break ;
41114088}
41124089
@@ -4244,7 +4221,7 @@ getAttrName(int attrnum, TableInfo *tblInfo)
42444221
42454222/*
42464223 * dumpIndexes:
4247- * write out to fout all the user-define indexes
4224+ * write out to fout all the user-defined indexes
42484225 */
42494226void
42504227dumpIndexes (Archive * fout ,IndInfo * indinfo ,int numIndexes ,
@@ -4447,13 +4424,14 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
44474424else
44484425appendPQExpBuffer (q ," %s )" ,attlist -> data );
44494426
4450- if (* indinfo [i ].indpred ) /* If there is an index predicate */
4427+ if (strcmp ( indinfo [i ].indhaspred , "t" ) == 0 )
44514428{
4429+ /* There is an index predicate, so fetch and dump it */
44524430int numRows ;
44534431PQExpBuffer pred = createPQExpBuffer ();
44544432
4455- appendPQExpBuffer (pred ,"SELECT pg_get_expr(indpred,indrelid) as pred FROM pg_index WHEREoid = %s" ,
4456- indinfo [i ].oid );
4433+ appendPQExpBuffer (pred ,"SELECT pg_get_expr(indpred,indrelid) as pred FROM pg_index WHEREindexrelid = %s" ,
4434+ indinfo [i ].indexreloid );
44574435res = PQexec (g_conn ,pred -> data );
44584436if (!res || PQresultStatus (res )!= PGRES_TUPLES_OK )
44594437{
@@ -4491,7 +4469,7 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
44914469/* Dump Index Comments */
44924470resetPQExpBuffer (q );
44934471appendPQExpBuffer (q ,"INDEX %s" ,id1 -> data );
4494- dumpComment (fout ,q -> data ,indinfo [i ].indoid );
4472+ dumpComment (fout ,q -> data ,indinfo [i ].indexreloid );
44954473
44964474}
44974475}