Cause ALTER INDEX OWNER to generate a warning and do nothing, rather than
authorTom Lane <tgl@sss.pgh.pa.us>
Mon, 22 Aug 2005 19:40:37 +0000 (19:40 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Mon, 22 Aug 2005 19:40:37 +0000 (19:40 +0000)
erroring out as it has done for the last couple weeks.  Document that this
form is now ignored because indexes can't usefully have different owners
from their parent tables.  Fix pg_dump to not generate ALTER OWNER commands
for indexes.

doc/src/sgml/ref/alter_index.sgml
src/backend/commands/tablecmds.c
src/bin/pg_dump/pg_backup_archiver.c

index e03931f1b484007e2f90801eb2e199a7e1696a6d..3a1997191c3b3009f12415260d497e6e46aaabb5 100644 (file)
@@ -20,13 +20,8 @@ PostgreSQL documentation
 
  <refsynopsisdiv>
 <synopsis>
-ALTER INDEX <replaceable class="PARAMETER">name</replaceable> <replaceable class="PARAMETER">action</replaceable> [, ... ]
 ALTER INDEX <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
-
-where <replaceable class="PARAMETER">action</replaceable> is one of:
-
-    OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
-    SET TABLESPACE <replaceable class="PARAMETER">indexspace_name</replaceable>
+ALTER INDEX <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">tablespace_name</replaceable>
 </synopsis>
  </refsynopsisdiv>
 
@@ -40,11 +35,11 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
   <variablelist>
 
    <varlistentry>
-    <term><literal>OWNER</literal></term>
+    <term><literal>RENAME</literal></term>
     <listitem>
      <para>
-      This form changes the owner of the index to the
-      specified user.  This can only be done by a superuser.
+      The <literal>RENAME</literal> form changes the name of the index. 
+      There is no effect on the stored data.
      </para>
     </listitem>
    </varlistentry>
@@ -61,24 +56,9 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
     </listitem>
    </varlistentry>
 
-   <varlistentry>
-    <term><literal>RENAME</literal></term>
-    <listitem>
-     <para>
-      The <literal>RENAME</literal> form changes the name of the index. 
-         There is no effect on the stored data.
-     </para>
-    </listitem>
-   </varlistentry>
-
   </variablelist>
   </para>
 
-  <para>
-   All the actions except <literal>RENAME</literal> can be combined into
-   a list of multiple alterations to apply in parallel.
-  </para>
-
  </refsect1>
 
  <refsect1>
@@ -90,28 +70,17 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
       <term><replaceable class="PARAMETER">name</replaceable></term>
       <listitem>
        <para>
-       The name (possibly schema-qualified) of an existing index to
-       alter.
+        The name (possibly schema-qualified) of an existing index to
+        alter.
        </para>
       </listitem>
      </varlistentry>
 
-
      <varlistentry>
       <term><replaceable class="PARAMETER">new_name</replaceable></term>
       <listitem>
        <para>
-       New name for the index.
-       </para>
-      </listitem>
-     </varlistentry>
-
-
-     <varlistentry>
-      <term><replaceable class="PARAMETER">new_owner</replaceable></term>
-      <listitem>
-       <para>
-       The user name of the new owner of the index.
+        New name for the index.
        </para>
       </listitem>
      </varlistentry>
@@ -120,7 +89,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
       <term><replaceable class="PARAMETER">tablespace_name</replaceable></term>
       <listitem>
        <para>
-       The tablespace name to which the index will be moved.
+        The tablespace to which the index will be moved.
        </para>
       </listitem>
      </varlistentry>
@@ -138,6 +107,13 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
     of <command>ALTER TABLE</> that apply to indexes.
    </para>
 
+   <para>
+    There was formerly an <command>ALTER INDEX OWNER</> variant, but
+    this is now ignored (with a warning).  An index cannot have an owner
+    different from its table's owner.  Changing the table's owner
+    automatically changes the index as well.
+   </para>
+
    <para>
     Changing any part of a system catalog index is not permitted.
    </para>
@@ -153,7 +129,7 @@ ALTER INDEX distributors RENAME TO suppliers;
   </para>
 
   <para> 
-       To move a index to a different tablespace:
+   To move an index to a different tablespace:
 <programlisting>
 ALTER INDEX distributors SET TABLESPACE fasttablespace;
 </programlisting>
index 28bb3a036011d970de0da4ab71087826a18546e1..5da6d63cb77a6dd1d622c489a60e5d0b0f57fcd1 100644 (file)
@@ -5279,6 +5279,25 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing)
                        /* ok to change owner */
                        break;
                case RELKIND_INDEX:
+                       if (!recursing)
+                       {
+                               /*
+                                * Because ALTER INDEX OWNER used to be allowed, and in fact
+                                * is generated by old versions of pg_dump, we give a warning
+                                * and do nothing rather than erroring out.  Also, to avoid
+                                * unnecessary chatter while restoring those old dumps, say
+                                * nothing at all if the command would be a no-op anyway.
+                                */
+                               if (tuple_class->relowner != newOwnerId)
+                                       ereport(WARNING,
+                                                       (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+                                                        errmsg("cannot change owner of index \"%s\"",
+                                                                       NameStr(tuple_class->relname)),
+                                                        errhint("Change the ownership of the index's table, instead.")));
+                               /* quick hack to exit via the no-op path */
+                               newOwnerId = tuple_class->relowner;
+                       }
+                       break;
                case RELKIND_TOASTVALUE:
                        if (recursing)
                                break;
index fcde31efc138bef3e46bbad8454310d564e68079..0ac58d96440aadb2b11afe2236926a2fc3d2f6d0 100644 (file)
@@ -2305,14 +2305,9 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te, ArchiveHandle *AH)
                strcmp(type, "SEQUENCE") == 0)
                type = "TABLE";
 
-       /* We assume CONSTRAINTs are always pkey/unique indexes */
-       if (strcmp(type, "CONSTRAINT") == 0)
-               type = "INDEX";
-
        /* objects named by a schema and name */
        if (strcmp(type, "CONVERSION") == 0 ||
                strcmp(type, "DOMAIN") == 0 ||
-               strcmp(type, "INDEX") == 0 ||
                strcmp(type, "TABLE") == 0 ||
                strcmp(type, "TYPE") == 0)
        {
@@ -2473,12 +2468,10 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
                strlen(te->owner) > 0 && strlen(te->dropStmt) > 0)
        {
                if (strcmp(te->desc, "AGGREGATE") == 0 ||
-                       strcmp(te->desc, "CONSTRAINT") == 0 ||
                        strcmp(te->desc, "CONVERSION") == 0 ||
                        strcmp(te->desc, "DATABASE") == 0 ||
                        strcmp(te->desc, "DOMAIN") == 0 ||
                        strcmp(te->desc, "FUNCTION") == 0 ||
-                       strcmp(te->desc, "INDEX") == 0 ||
                        strcmp(te->desc, "OPERATOR") == 0 ||
                        strcmp(te->desc, "OPERATOR CLASS") == 0 ||
                        strcmp(te->desc, "SCHEMA") == 0 ||
@@ -2497,8 +2490,10 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
                }
                else if (strcmp(te->desc, "CAST") == 0 ||
                                 strcmp(te->desc, "CHECK CONSTRAINT") == 0 ||
+                                strcmp(te->desc, "CONSTRAINT") == 0 ||
                                 strcmp(te->desc, "DEFAULT") == 0 ||
                                 strcmp(te->desc, "FK CONSTRAINT") == 0 ||
+                                strcmp(te->desc, "INDEX") == 0 ||
                                 strcmp(te->desc, "PROCEDURAL LANGUAGE") == 0 ||
                                 strcmp(te->desc, "RULE") == 0 ||
                                 strcmp(te->desc, "TRIGGER") == 0)