]> granicus.if.org Git - postgresql/commitdiff
Used LEFT OUTER JOIN for various queries
authorPhilip Warner <pjw@rhyme.com.au>
Sun, 28 Jan 2001 03:47:49 +0000 (03:47 +0000)
committerPhilip Warner <pjw@rhyme.com.au>
Sun, 28 Jan 2001 03:47:49 +0000 (03:47 +0000)
src/bin/pg_dump/common.c
src/bin/pg_dump/pg_backup_archiver.h
src/bin/pg_dump/pg_dump.c

index d91b435be4c6f72fe1716509e9b34607c6b29ab4..c7658f384e8f7e9613b0364e7d785eca0de107a1 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.51 2001/01/28 02:57:06 pjw Exp $
+ *       $Header: /cvsroot/pgsql/src/bin/pg_dump/common.c,v 1.52 2001/01/28 03:47:49 pjw Exp $
  *
  * Modifications - 6/12/96 - dave@bensoft.com - version 1.13.dhb.2
  *
index 583ab8dac738dffc4fb83cb53d4da1b95d79bbd1..e7f18d1bbff79eff8ae23ee894bd5b0e507a69a0 100644 (file)
@@ -62,7 +62,7 @@ typedef z_stream *z_streamp;
 
 #define K_VERS_MAJOR 1
 #define K_VERS_MINOR 4 
-#define K_VERS_REV 25 
+#define K_VERS_REV 27 
 
 /* Data block types */
 #define BLK_DATA 1
index 6f38692e548a069ec95bd157af800093d9c9ca4a..1822b4200d4359be8e6a31a47d2b11cb2ce97cc9 100644 (file)
@@ -22,7 +22,7 @@
  *
  *
  * IDENTIFICATION
- *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.189 2001/01/28 02:57:06 pjw Exp $
+ *       $Header: /cvsroot/pgsql/src/bin/pg_dump/pg_dump.c,v 1.190 2001/01/28 03:47:49 pjw Exp $
  *
  * Modifications - 6/10/96 - dave@bensoft.com - version 1.13.dhb
  *
@@ -2037,6 +2037,7 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
                                                tblinfo[i].relname,
                                                g_comment_end);
 
+                       /* XXXX: Use LOJ maybe - need to compare with subsequent query for non-inherited */
                        resetPQExpBuffer(query);
                        appendPQExpBuffer(query, "SELECT rcname from pg_relcheck, pg_inherits as i "
                                                          "where rcrelid = '%s'::oid "
@@ -2141,13 +2142,14 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
                        res2 = PQexec(g_conn, query->data);
                        if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK)
                        {
-                               fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY) failed.  Explanation from backend: %s\n",
-                                               PQerrorMessage(g_conn));
+                               fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY) failed on table %s.  Explanation from backend: %s\n",
+                                               tblinfo[i].relname, PQerrorMessage(g_conn));
                                exit_nicely(g_conn);
                        }
 
                        if (PQntuples(res2) > 1) {
-                               fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY) produced more than one row.\n");
+                               fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY) produced more than one row on table %s.\n",
+                                               tblinfo[i].relname);
                                exit_nicely(g_conn);
                        }
 
@@ -2170,16 +2172,15 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
                        resetPQExpBuffer(query);
                        appendPQExpBuffer(query,
                                                          "SELECT c.relname "
-                                                         "FROM pg_index i, pg_class c "
+                                                         "FROM pg_index i LEFT OUTER JOIN pg_class c ON c.oid = i.indexrelid "
                                                          "WHERE i.indrelid = %s"
-                                                         "AND   i.indisprimary "
-                                                         "AND   c.oid = i.indexrelid ",
+                                                         "AND   i.indisprimary ",
                                                          tblinfo[i].oid);
                        res2 = PQexec(g_conn, query->data);
                        if (!res2 || PQresultStatus(res2) != PGRES_TUPLES_OK)
                        {
-                               fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY NAME) failed.  Explanation from backend: %s",
-                                               PQerrorMessage(g_conn));
+                               fprintf(stderr, "getTables(): SELECT (for PRIMARY KEY NAME) failed for table %s.  Explanation from backend: %s",
+                                               tblinfo[i].relname, PQerrorMessage(g_conn));
                                exit_nicely(g_conn);
                        }
 
@@ -2187,12 +2188,22 @@ getTables(int *numTables, FuncInfo *finfo, int numFuncs)
                        if (n != 1)
                        {
                                fprintf(stderr,
-                                               "getTables(): SELECT (for PRIMARY KEY NAME) failed. This is impossible but object with OID == %s have %d primary keys.\n",
+                                               "getTables(): SELECT (for PRIMARY KEY NAME) failed for table %s. "
+                                                       "This is impossible but object with OID == %s have %d primary keys.\n",
+                                               tblinfo[i].relname,
                                                tblinfo[i].oid,
                                                n);
                                exit_nicely(g_conn);
                        }
 
+                       /* Sanity check on LOJ */
+                       if (PQgetisnull(res2, 0, 0))
+                       {
+                               fprintf(stderr,"getTables(): SELECT (for PRIMARY KEY NAME) on table %s returned NULL value.\n",
+                                               tblinfo[i].relname);
+                               exit_nicely(g_conn);
+                       }
+
                        tblinfo[i].primary_key_name =
                                strdup(fmtId(PQgetvalue(res2, 0, 0), force_quotes));
                        if (tblinfo[i].primary_key_name == NULL)
@@ -2569,8 +2580,8 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
                resetPQExpBuffer(q);
                appendPQExpBuffer(q, "SELECT a.oid as attoid, a.attnum, a.attname, t.typname, a.atttypmod, "
                                                  "a.attnotnull, a.atthasdef, format_type(a.atttypid, a.atttypmod) as atttypedefn "
-                                                 "from pg_attribute a, pg_type t "
-                                  "where a.attrelid = '%s'::oid and a.atttypid = t.oid "
+                                                 "from pg_attribute a LEFT OUTER JOIN pg_type t ON a.atttypid = t.oid "
+                                  "where a.attrelid = '%s'::oid "
                                                  "and a.attnum > 0 order by attnum",
                                                  tblinfo[i].oid);
                res = PQexec(g_conn, q->data);
@@ -2605,6 +2616,15 @@ getTableAttrs(TableInfo *tblinfo, int numTables)
                tblinfo[i].numParents = 0;
                for (j = 0; j < ntups; j++)
                {
+
+                       /* Sanity check on LOJ */
+                       if (PQgetisnull(res, j, i_typname))
+                       {
+                               fprintf(stderr, "getTableAttrs(): SELECT produced NULL attribute type name for attr %d on table %s.\n",
+                                               j, tblinfo[i].relname);
+                               exit_nicely(g_conn);
+                       }
+
                        tblinfo[i].attoids[j] = strdup(PQgetvalue(res, j, i_attoid));
                        tblinfo[i].attnames[j] = strdup(PQgetvalue(res, j, i_attname));
                        tblinfo[i].atttypedefns[j] = strdup(PQgetvalue(res, j, i_atttypedefn));
@@ -2692,6 +2712,8 @@ getIndices(int *numIndices)
         * Notice we skip indices on system classes
         *
         * this is a 4-way join !!
+        *
+        * XXXX: Use LOJ
         */
 
        appendPQExpBuffer(query,
@@ -4423,6 +4445,8 @@ dumpRules(Archive *fout, const char *tablename,
                 * Get all rules defined for this table
                 * We include pg_rules in the cross since it filters out
                 * all view rules (pjw 15-Sep-2000).
+                *
+                * XXXX: Use LOJ here
                 */
                resetPQExpBuffer(query);
                appendPQExpBuffer(query, "SELECT definition,"