Skip to content

Commit 83357da

Browse files
committed
Cause ALTER INDEX OWNER to generate a warning and do nothing, rather than
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.
1 parent bf1e33d commit 83357da

File tree

3 files changed

+40
-50
lines changed

3 files changed

+40
-50
lines changed

doc/src/sgml/ref/alter_index.sgml

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_index.sgml,v 1.5 2005/03/14 00:19:36 neilc Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/alter_index.sgml,v 1.6 2005/08/22 19:39:52 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -20,13 +20,8 @@ PostgreSQL documentation
2020

2121
<refsynopsisdiv>
2222
<synopsis>
23-
ALTER INDEX <replaceable class="PARAMETER">name</replaceable> <replaceable class="PARAMETER">action</replaceable> [, ... ]
2423
ALTER INDEX <replaceable class="PARAMETER">name</replaceable> RENAME TO <replaceable class="PARAMETER">new_name</replaceable>
25-
26-
where <replaceable class="PARAMETER">action</replaceable> is one of:
27-
28-
OWNER TO <replaceable class="PARAMETER">new_owner</replaceable>
29-
SET TABLESPACE <replaceable class="PARAMETER">indexspace_name</replaceable>
24+
ALTER INDEX <replaceable class="PARAMETER">name</replaceable> SET TABLESPACE <replaceable class="PARAMETER">tablespace_name</replaceable>
3025
</synopsis>
3126
</refsynopsisdiv>
3227

@@ -40,11 +35,11 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
4035
<variablelist>
4136

4237
<varlistentry>
43-
<term><literal>OWNER</literal></term>
38+
<term><literal>RENAME</literal></term>
4439
<listitem>
4540
<para>
46-
This form changes the owner of the index to the
47-
specified user. This can only be done by a superuser.
41+
The <literal>RENAME</literal> form changes the name of the index.
42+
There is no effect on the stored data.
4843
</para>
4944
</listitem>
5045
</varlistentry>
@@ -61,24 +56,9 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
6156
</listitem>
6257
</varlistentry>
6358

64-
<varlistentry>
65-
<term><literal>RENAME</literal></term>
66-
<listitem>
67-
<para>
68-
The <literal>RENAME</literal> form changes the name of the index.
69-
There is no effect on the stored data.
70-
</para>
71-
</listitem>
72-
</varlistentry>
73-
7459
</variablelist>
7560
</para>
7661

77-
<para>
78-
All the actions except <literal>RENAME</literal> can be combined into
79-
a list of multiple alterations to apply in parallel.
80-
</para>
81-
8262
</refsect1>
8363

8464
<refsect1>
@@ -90,28 +70,17 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
9070
<term><replaceable class="PARAMETER">name</replaceable></term>
9171
<listitem>
9272
<para>
93-
The name (possibly schema-qualified) of an existing index to
94-
alter.
73+
The name (possibly schema-qualified) of an existing index to
74+
alter.
9575
</para>
9676
</listitem>
9777
</varlistentry>
9878

99-
10079
<varlistentry>
10180
<term><replaceable class="PARAMETER">new_name</replaceable></term>
10281
<listitem>
10382
<para>
104-
New name for the index.
105-
</para>
106-
</listitem>
107-
</varlistentry>
108-
109-
110-
<varlistentry>
111-
<term><replaceable class="PARAMETER">new_owner</replaceable></term>
112-
<listitem>
113-
<para>
114-
The user name of the new owner of the index.
83+
New name for the index.
11584
</para>
11685
</listitem>
11786
</varlistentry>
@@ -120,7 +89,7 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
12089
<term><replaceable class="PARAMETER">tablespace_name</replaceable></term>
12190
<listitem>
12291
<para>
123-
The tablespace name to which the index will be moved.
92+
The tablespace to which the index will be moved.
12493
</para>
12594
</listitem>
12695
</varlistentry>
@@ -138,6 +107,13 @@ where <replaceable class="PARAMETER">action</replaceable> is one of:
138107
of <command>ALTER TABLE</> that apply to indexes.
139108
</para>
140109

110+
<para>
111+
There was formerly an <command>ALTER INDEX OWNER</> variant, but
112+
this is now ignored (with a warning). An index cannot have an owner
113+
different from its table's owner. Changing the table's owner
114+
automatically changes the index as well.
115+
</para>
116+
141117
<para>
142118
Changing any part of a system catalog index is not permitted.
143119
</para>
@@ -153,7 +129,7 @@ ALTER INDEX distributors RENAME TO suppliers;
153129
</para>
154130

155131
<para>
156-
To move a index to a different tablespace:
132+
To move an index to a different tablespace:
157133
<programlisting>
158134
ALTER INDEX distributors SET TABLESPACE fasttablespace;
159135
</programlisting>

src/backend/commands/tablecmds.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.167 2005/08/22 17:38:20 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.168 2005/08/22 19:40:09 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -5279,6 +5279,25 @@ ATExecChangeOwner(Oid relationOid, Oid newOwnerId, bool recursing)
52795279
/* ok to change owner */
52805280
break;
52815281
case RELKIND_INDEX:
5282+
if (!recursing)
5283+
{
5284+
/*
5285+
* Because ALTER INDEX OWNER used to be allowed, and in fact
5286+
* is generated by old versions of pg_dump, we give a warning
5287+
* and do nothing rather than erroring out. Also, to avoid
5288+
* unnecessary chatter while restoring those old dumps, say
5289+
* nothing at all if the command would be a no-op anyway.
5290+
*/
5291+
if (tuple_class->relowner != newOwnerId)
5292+
ereport(WARNING,
5293+
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
5294+
errmsg("cannot change owner of index \"%s\"",
5295+
NameStr(tuple_class->relname)),
5296+
errhint("Change the ownership of the index's table, instead.")));
5297+
/* quick hack to exit via the no-op path */
5298+
newOwnerId = tuple_class->relowner;
5299+
}
5300+
break;
52825301
case RELKIND_TOASTVALUE:
52835302
if (recursing)
52845303
break;

src/bin/pg_dump/pg_backup_archiver.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.112 2005/08/12 01:35:59 tgl Exp $
18+
* $PostgreSQL: pgsql/src/bin/pg_dump/pg_backup_archiver.c,v 1.113 2005/08/22 19:40:37 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2305,14 +2305,9 @@ _getObjectDescription(PQExpBuffer buf, TocEntry *te, ArchiveHandle *AH)
23052305
strcmp(type, "SEQUENCE") == 0)
23062306
type = "TABLE";
23072307

2308-
/* We assume CONSTRAINTs are always pkey/unique indexes */
2309-
if (strcmp(type, "CONSTRAINT") == 0)
2310-
type = "INDEX";
2311-
23122308
/* objects named by a schema and name */
23132309
if (strcmp(type, "CONVERSION") == 0 ||
23142310
strcmp(type, "DOMAIN") == 0 ||
2315-
strcmp(type, "INDEX") == 0 ||
23162311
strcmp(type, "TABLE") == 0 ||
23172312
strcmp(type, "TYPE") == 0)
23182313
{
@@ -2473,12 +2468,10 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
24732468
strlen(te->owner) > 0 && strlen(te->dropStmt) > 0)
24742469
{
24752470
if (strcmp(te->desc, "AGGREGATE") == 0 ||
2476-
strcmp(te->desc, "CONSTRAINT") == 0 ||
24772471
strcmp(te->desc, "CONVERSION") == 0 ||
24782472
strcmp(te->desc, "DATABASE") == 0 ||
24792473
strcmp(te->desc, "DOMAIN") == 0 ||
24802474
strcmp(te->desc, "FUNCTION") == 0 ||
2481-
strcmp(te->desc, "INDEX") == 0 ||
24822475
strcmp(te->desc, "OPERATOR") == 0 ||
24832476
strcmp(te->desc, "OPERATOR CLASS") == 0 ||
24842477
strcmp(te->desc, "SCHEMA") == 0 ||
@@ -2497,8 +2490,10 @@ _printTocEntry(ArchiveHandle *AH, TocEntry *te, RestoreOptions *ropt, bool isDat
24972490
}
24982491
else if (strcmp(te->desc, "CAST") == 0 ||
24992492
strcmp(te->desc, "CHECK CONSTRAINT") == 0 ||
2493+
strcmp(te->desc, "CONSTRAINT") == 0 ||
25002494
strcmp(te->desc, "DEFAULT") == 0 ||
25012495
strcmp(te->desc, "FK CONSTRAINT") == 0 ||
2496+
strcmp(te->desc, "INDEX") == 0 ||
25022497
strcmp(te->desc, "PROCEDURAL LANGUAGE") == 0 ||
25032498
strcmp(te->desc, "RULE") == 0 ||
25042499
strcmp(te->desc, "TRIGGER") == 0)

0 commit comments

Comments
 (0)