Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3e896eb

Browse files
committed
Used LEFT OUTER JOIN for various queries
1 parent 2f9bdff commit 3e896eb

File tree

3 files changed

+38
-14
lines changed

3 files changed

+38
-14
lines changed

src/bin/pg_dump/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.51 2001/01/28 02:57:06 pjw Exp $
11+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.52 2001/01/28 03:47:49 pjw Exp $
1212
*
1313
* Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
1414
*

src/bin/pg_dump/pg_backup_archiver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
6262

6363
#define K_VERS_MAJOR 1
6464
#define K_VERS_MINOR 4
65-
#define K_VERS_REV 25
65+
#define K_VERS_REV 27
6666

6767
/* Data block types */
6868
#define BLK_DATA 1

src/bin/pg_dump/pg_dump.c

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
*
2323
*
2424
* IDENTIFICATION
25-
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.189 2001/01/28 02:57:06 pjw Exp $
25+
* $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.190 2001/01/28 03:47:49 pjw Exp $
2626
*
2727
* Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
2828
*
@@ -2037,6 +2037,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
20372037
tblinfo[i].relname,
20382038
g_comment_end);
20392039

2040+
/* XXXX: Use LOJ maybe - need to compare with subsequent query for non-inherited */
20402041
resetPQExpBuffer(query);
20412042
appendPQExpBuffer(query, "SELECT rcname from pg_relcheck, pg_inherits as i "
20422043
"where rcrelid = '%s'::oid "
@@ -2141,13 +2142,14 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
21412142
res2 = PQexec(g_conn, query->data);
21422143
if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK)
21432144
{
2144-
fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY) failed. Explanation from backend: %s\n",
2145-
PQerrorMessage(g_conn));
2145+
fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY) failed on table %s. Explanation from backend: %s\n",
2146+
tblinfo[i].relname, PQerrorMessage(g_conn));
21462147
exit_nicely(g_conn);
21472148
}
21482149

21492150
if (PQntuples(res2) > 1) {
2150-
fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY) produced more than one row.\n");
2151+
fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY) produced more than one row on table %s.\n",
2152+
tblinfo[i].relname);
21512153
exit_nicely(g_conn);
21522154
}
21532155

@@ -2170,29 +2172,38 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
21702172
resetPQExpBuffer(query);
21712173
appendPQExpBuffer(query,
21722174
"SELECT c.relname "
2173-
"FROM pg_index i, pg_class c "
2175+
"FROM pg_index i LEFT OUTER JOIN pg_class c ON c.oid = i.indexrelid "
21742176
"WHERE i.indrelid = %s"
2175-
"AND i.indisprimary "
2176-
"AND c.oid = i.indexrelid ",
2177+
"AND i.indisprimary ",
21772178
tblinfo[i].oid);
21782179
res2 = PQexec(g_conn, query->data);
21792180
if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK)
21802181
{
2181-
fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY NAME) failed. Explanation from backend: %s",
2182-
PQerrorMessage(g_conn));
2182+
fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY NAME) failed for table %s. Explanation from backend: %s",
2183+
tblinfo[i].relname, PQerrorMessage(g_conn));
21832184
exit_nicely(g_conn);
21842185
}
21852186

21862187
n = PQntuples(res2);
21872188
if (n != 1)
21882189
{
21892190
fprintf(stderr,
2190-
"getTables(): SELECT (for PRIMARY KEY NAME) failed. This is impossible but object with OID == %s have %d primary keys.\n",
2191+
"getTables(): SELECT (for PRIMARY KEY NAME) failed for table %s. "
2192+
"This is impossible but object with OID == %s have %d primary keys.\n",
2193+
tblinfo[i].relname,
21912194
tblinfo[i].oid,
21922195
n);
21932196
exit_nicely(g_conn);
21942197
}
21952198

2199+
/* Sanity check on LOJ */
2200+
if (PQgetisnull(res2, 0, 0))
2201+
{
2202+
fprintf(stderr,"getTables(): SELECT (for PRIMARY KEY NAME) on table %s returned NULL value.\n",
2203+
tblinfo[i].relname);
2204+
exit_nicely(g_conn);
2205+
}
2206+
21962207
tblinfo[i].primary_key_name =
21972208
strdup(fmtId(PQgetvalue(res2, 0, 0), force_quotes));
21982209
if (tblinfo[i].primary_key_name == NULL)
@@ -2569,8 +2580,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
25692580
resetPQExpBuffer(q);
25702581
appendPQExpBuffer(q, "SELECT a.oid as attoid, a.attnum, a.attname, t.typname, a.atttypmod, "
25712582
"a.attnotnull, a.atthasdef, format_type(a.atttypid, a.atttypmod) as atttypedefn "
2572-
"from pg_attribute a, pg_type t "
2573-
"where a.attrelid = '%s'::oid and a.atttypid = t.oid "
2583+
"from pg_attribute a LEFT OUTER JOIN pg_type t ON a.atttypid = t.oid "
2584+
"where a.attrelid = '%s'::oid "
25742585
"and a.attnum > 0 order by attnum",
25752586
tblinfo[i].oid);
25762587
res = PQexec(g_conn, q->data);
@@ -2605,6 +2616,15 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
26052616
tblinfo[i].numParents = 0;
26062617
for (j = 0; j < ntups; j++)
26072618
{
2619+
2620+
/* Sanity check on LOJ */
2621+
if (PQgetisnull(res, j, i_typname))
2622+
{
2623+
fprintf(stderr, "getTableAttrs(): SELECT produced NULL attribute type name for attr %d on table %s.\n",
2624+
j, tblinfo[i].relname);
2625+
exit_nicely(g_conn);
2626+
}
2627+
26082628
tblinfo[i].attoids[j] = strdup(PQgetvalue(res, j, i_attoid));
26092629
tblinfo[i].attnames[j] = strdup(PQgetvalue(res, j, i_attname));
26102630
tblinfo[i].atttypedefns[j] = strdup(PQgetvalue(res, j, i_atttypedefn));
@@ -2692,6 +2712,8 @@ getIndices(int *numIndices)
26922712
* Notice we skip indices on system classes
26932713
*
26942714
* this is a 4-way join !!
2715+
*
2716+
* XXXX: Use LOJ
26952717
*/
26962718

26972719
appendPQExpBuffer(query,
@@ -4423,6 +4445,8 @@ dumpRules(Archive *fout, const char *tablename,
44234445
* Get all rules defined for this table
44244446
* We include pg_rules in the cross since it filters out
44254447
* all view rules (pjw 15-Sep-2000).
4448+
*
4449+
* XXXX: Use LOJ here
44264450
*/
44274451
resetPQExpBuffer(query);
44284452
appendPQExpBuffer(query, "SELECT definition,"

0 commit comments

Comments
 (0)