22
22
*
23
23
*
24
24
* 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 $
26
26
*
27
27
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
28
28
*
@@ -1744,8 +1744,10 @@ clearIndInfo(IndInfo *ind, int numIndexes)
1744
1744
return ;
1745
1745
for (i = 0 ; i < numIndexes ; ++ i )
1746
1746
{
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 );
1749
1751
if (ind [i ].indexrelname )
1750
1752
free (ind [i ].indexrelname );
1751
1753
if (ind [i ].indrelname )
@@ -1758,8 +1760,8 @@ clearIndInfo(IndInfo *ind, int numIndexes)
1758
1760
free (ind [i ].indisunique );
1759
1761
if (ind [i ].indisprimary )
1760
1762
free (ind [i ].indisprimary );
1761
- if (ind [i ].indpred )
1762
- free (ind [i ].indpred );
1763
+ if (ind [i ].indhaspred )
1764
+ free (ind [i ].indhaspred );
1763
1765
for (a = 0 ; a < INDEX_MAX_KEYS ; ++ a )
1764
1766
{
1765
1767
if (ind [i ].indkey [a ])
@@ -2264,7 +2266,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2264
2266
2265
2267
resetPQExpBuffer (query );
2266
2268
appendPQExpBuffer (query ,
2267
- "SELECT Oid FROM pg_index i WHERE i.indisprimary AND i.indrelid = %s " ,
2269
+ "SELECT indexrelid FROM pg_index i WHERE i.indisprimary AND i.indrelid = %s " ,
2268
2270
tblinfo [i ].oid );
2269
2271
res2 = PQexec (g_conn , query -> data );
2270
2272
if (!res2 || PQresultStatus (res2 ) != PGRES_TUPLES_OK )
@@ -2297,31 +2299,10 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2297
2299
int n ;
2298
2300
2299
2301
resetPQExpBuffer (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 );
2325
2306
2326
2307
res2 = PQexec (g_conn , query -> data );
2327
2308
if (!res2 || PQresultStatus (res2 ) != PGRES_TUPLES_OK )
@@ -2339,14 +2320,6 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
2339
2320
exit_nicely ();
2340
2321
}
2341
2322
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
-
2350
2323
tblinfo [i ].primary_key_name =
2351
2324
strdup (fmtId (PQgetvalue (res2 , 0 , 0 ), force_quotes ));
2352
2325
if (tblinfo [i ].primary_key_name == NULL )
@@ -2879,17 +2852,17 @@ getIndexes(int *numIndexes)
2879
2852
int ntups ;
2880
2853
IndInfo * indinfo ;
2881
2854
2855
+ int i_indexreloid ;
2856
+ int i_indreloid ;
2882
2857
int i_indexrelname ;
2883
2858
int i_indrelname ;
2884
2859
int i_indamname ;
2885
2860
int i_indproc ;
2886
2861
int i_indkey ;
2887
2862
int i_indclass ;
2888
2863
int i_indisunique ;
2889
- int i_indoid ;
2890
- int i_oid ;
2891
2864
int i_indisprimary ;
2892
- int i_indpred ;
2865
+ int i_indhaspred ;
2893
2866
2894
2867
/*
2895
2868
* find all the user-defined indexes.
@@ -2902,11 +2875,14 @@ getIndexes(int *numIndexes)
2902
2875
*/
2903
2876
2904
2877
appendPQExpBuffer (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, "
2906
2881
"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 "
2910
2886
"and t1.relam = a.oid and i.indexrelid > '%u'::oid "
2911
2887
"and t2.relname !~ '^pg_' " ,
2912
2888
g_last_builtin_oid );
@@ -2930,8 +2906,8 @@ getIndexes(int *numIndexes)
2930
2906
2931
2907
memset ((char * ) indinfo , 0 , ntups * sizeof (IndInfo ));
2932
2908
2933
- i_oid = PQfnumber (res , "oid " );
2934
- i_indoid = PQfnumber (res , "indoid " );
2909
+ i_indexreloid = PQfnumber (res , "indexreloid " );
2910
+ i_indreloid = PQfnumber (res , "indreloid " );
2935
2911
i_indexrelname = PQfnumber (res , "indexrelname" );
2936
2912
i_indrelname = PQfnumber (res , "indrelname" );
2937
2913
i_indamname = PQfnumber (res , "indamname" );
@@ -2940,12 +2916,12 @@ getIndexes(int *numIndexes)
2940
2916
i_indclass = PQfnumber (res , "indclass" );
2941
2917
i_indisunique = PQfnumber (res , "indisunique" );
2942
2918
i_indisprimary = PQfnumber (res , "indisprimary" );
2943
- i_indpred = PQfnumber (res , "indpred " );
2919
+ i_indhaspred = PQfnumber (res , "indhaspred " );
2944
2920
2945
2921
for (i = 0 ; i < ntups ; i ++ )
2946
2922
{
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 ));
2949
2925
indinfo [i ].indexrelname = strdup (PQgetvalue (res , i , i_indexrelname ));
2950
2926
indinfo [i ].indrelname = strdup (PQgetvalue (res , i , i_indrelname ));
2951
2927
indinfo [i ].indamname = strdup (PQgetvalue (res , i , i_indamname ));
@@ -2958,7 +2934,7 @@ getIndexes(int *numIndexes)
2958
2934
INDEX_MAX_KEYS );
2959
2935
indinfo [i ].indisunique = strdup (PQgetvalue (res , i , i_indisunique ));
2960
2936
indinfo [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 ));
2962
2938
}
2963
2939
PQclear (res );
2964
2940
return indinfo ;
@@ -4106,7 +4082,8 @@ dumpTables(Archive *fout, TableInfo *tblinfo, int numTables,
4106
4082
/* Find the corresponding index */
4107
4083
for (k = 0 ; k < numIndexes ; k ++ )
4108
4084
{
4109
- if (strcmp (indinfo [k ].oid , tblinfo [i ].pkIndexOid ) == 0 )
4085
+ if (strcmp (indinfo [k ].indexreloid ,
4086
+ tblinfo [i ].pkIndexOid ) == 0 )
4110
4087
break ;
4111
4088
}
4112
4089
@@ -4244,7 +4221,7 @@ getAttrName(int attrnum, TableInfo *tblInfo)
4244
4221
4245
4222
/*
4246
4223
* dumpIndexes:
4247
- * write out to fout all the user-define indexes
4224
+ * write out to fout all the user-defined indexes
4248
4225
*/
4249
4226
void
4250
4227
dumpIndexes (Archive * fout , IndInfo * indinfo , int numIndexes ,
@@ -4447,13 +4424,14 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
4447
4424
else
4448
4425
appendPQExpBuffer (q , " %s )" , attlist -> data );
4449
4426
4450
- if (* indinfo [i ].indpred ) /* If there is an index predicate */
4427
+ if (strcmp ( indinfo [i ].indhaspred , "t" ) == 0 )
4451
4428
{
4429
+ /* There is an index predicate, so fetch and dump it */
4452
4430
int numRows ;
4453
4431
PQExpBuffer pred = createPQExpBuffer ();
4454
4432
4455
- appendPQExpBuffer (pred , "SELECT pg_get_expr(indpred,indrelid) as pred FROM pg_index WHERE oid = %s" ,
4456
- indinfo [i ].oid );
4433
+ appendPQExpBuffer (pred , "SELECT pg_get_expr(indpred,indrelid) as pred FROM pg_index WHERE indexrelid = %s" ,
4434
+ indinfo [i ].indexreloid );
4457
4435
res = PQexec (g_conn , pred -> data );
4458
4436
if (!res || PQresultStatus (res ) != PGRES_TUPLES_OK )
4459
4437
{
@@ -4491,7 +4469,7 @@ dumpIndexes(Archive *fout, IndInfo *indinfo, int numIndexes,
4491
4469
/* Dump Index Comments */
4492
4470
resetPQExpBuffer (q );
4493
4471
appendPQExpBuffer (q , "INDEX %s" , id1 -> data );
4494
- dumpComment (fout , q -> data , indinfo [i ].indoid );
4472
+ dumpComment (fout , q -> data , indinfo [i ].indexreloid );
4495
4473
4496
4474
}
4497
4475
}
0 commit comments