Skip to content

Commit 8d54c24

Browse files
committed
Code review for LIKE INCLUDING patch --- clean up some cosmetic and not
so cosmetic stuff.
1 parent 5ec1341 commit 8d54c24

File tree

11 files changed

+73
-75
lines changed

11 files changed

+73
-75
lines changed

doc/src/sgml/ref/create_table.sgml

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.117 2009/10/12 19:49:24 adunstan Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/ref/create_table.sgml,v 1.118 2009/10/13 00:53:07 tgl Exp $
33
PostgreSQL documentation
44
-->
55

@@ -231,7 +231,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
231231
</para>
232232

233233
<para>
234-
Column storage parameters are also copied from parent tables.
234+
Column <literal>STORAGE</> settings are also copied from parent tables.
235235
</para>
236236

237237
<!--
@@ -285,25 +285,27 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
285285
specified.
286286
</para>
287287
<para>
288-
Storage parameters for the copied column definitions will only be copied
289-
if <literal>INCLUDING STORAGE</literal> is specified. The default
290-
behavior is to exclude storage parameters, resulting in the copied
291-
columns in the new table having type-specific default parameters. For
292-
more on storage parameters, see <xref linkend="storage-toast">.
288+
<literal>STORAGE</> settings for the copied column definitions will only
289+
be copied if <literal>INCLUDING STORAGE</literal> is specified. The
290+
default behavior is to exclude <literal>STORAGE</> settings, resulting
291+
in the copied columns in the new table having type-specific default
292+
settings. For more on <literal>STORAGE</> settings, see
293+
<xref linkend="storage-toast">.
293294
</para>
294295
<para>
295-
Comments for the copied column, constraint, index and columns of index
296-
definitions will only be copied if <literal>INCLUDING COMMENTS</literal>
297-
is specified. The default behavior is to exclude comments, resulting in
298-
the copied columns and constraints in the new table having no comments.
296+
Comments for the copied columns, constraints, and indexes
297+
will only be copied if <literal>INCLUDING COMMENTS</literal>
298+
is specified. The default behavior is to exclude comments, resulting in
299+
the copied columns and constraints in the new table having no comments.
299300
</para>
300301
<para>
301302
<literal>INCLUDING ALL</literal> is an abbreviated form of
302303
<literal>INCLUDING DEFAULTS INCLUDING CONSTRAINTS INCLUDING INDEXES INCLUDING STORAGE INCLUDING COMMENTS</literal>.
303304
</para>
304305
<para>
305-
Note also that unlike <literal>INHERITS</literal>, copied columns and
306-
constraints are not merged with similarly named columns and constraints.
306+
Note also that unlike <literal>INHERITS</literal>, columns and
307+
constraints copied by <literal>LIKE</> are not merged with similarly
308+
named columns and constraints.
307309
If the same name is specified explicitly or in another
308310
<literal>LIKE</literal> clause, an error is signalled.
309311
</para>
@@ -752,14 +754,14 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
752754
<para>
753755
Enables or disables the autovacuum daemon on a particular table.
754756
If true, the autovacuum daemon will initiate a <command>VACUUM</> operation
755-
on a particular table when the number of updated or deleted tuples exceeds
756-
<literal>autovacuum_vacuum_threshold</> plus
757-
<literal>autovacuum_vacuum_scale_factor</> times the number of live tuples
757+
on a particular table when the number of updated or deleted tuples exceeds
758+
<literal>autovacuum_vacuum_threshold</> plus
759+
<literal>autovacuum_vacuum_scale_factor</> times the number of live tuples
758760
currently estimated to be in the relation.
759761
Similarly, it will initiate an <command>ANALYZE</> operation when the
760762
number of inserted, updated or deleted tuples exceeds
761-
<literal>autovacuum_analyze_threshold</> plus
762-
<literal>autovacuum_analyze_scale_factor</> times the number of live tuples
763+
<literal>autovacuum_analyze_threshold</> plus
764+
<literal>autovacuum_analyze_scale_factor</> times the number of live tuples
763765
currently estimated to be in the relation.
764766
If false, this table will not be autovacuumed, except to prevent
765767
transaction Id wraparound. See <xref linkend="vacuum-for-wraparound"> for
@@ -775,7 +777,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
775777
<listitem>
776778
<para>
777779
Minimum number of updated or deleted tuples before initiate a
778-
<command>VACUUM</> operation on a particular table.
780+
<command>VACUUM</> operation on a particular table.
779781
</para>
780782
</listitem>
781783
</varlistentry>
@@ -834,7 +836,7 @@ CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } ] TABLE <replaceable class="PAR
834836
<para>
835837
Custom <xref linkend="guc-vacuum-freeze-min-age"> parameter. Note that
836838
autovacuum will ignore attempts to set a per-table
837-
<literal>autovacuum_freeze_min_age</> larger than the half system-wide
839+
<literal>autovacuum_freeze_min_age</> larger than the half system-wide
838840
<xref linkend="guc-autovacuum-freeze-max-age"> setting.
839841
</para>
840842
</listitem>

src/backend/access/common/tupdesc.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.129 2009/10/12 19:49:24 adunstan Exp $
11+
* $PostgreSQL: pgsql/src/backend/access/common/tupdesc.c,v 1.130 2009/10/13 00:53:07 tgl Exp $
1212
*
1313
* NOTES
1414
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -553,13 +553,15 @@ BuildDescForRelation(List *schema)
553553
TupleDescInitEntry(desc, attnum, attname,
554554
atttypid, atttypmod, attdim);
555555

556+
/* Override TupleDescInitEntry's settings as requested */
557+
if (entry->storage)
558+
desc->attrs[attnum - 1]->attstorage = entry->storage;
559+
556560
/* Fill in additional stuff not handled by TupleDescInitEntry */
557561
desc->attrs[attnum - 1]->attnotnull = entry->is_not_null;
558562
has_not_null |= entry->is_not_null;
559563
desc->attrs[attnum - 1]->attislocal = entry->is_local;
560564
desc->attrs[attnum - 1]->attinhcount = entry->inhcount;
561-
if (entry->storage)
562-
desc->attrs[attnum - 1]->attstorage = entry->storage;
563565
}
564566

565567
if (has_not_null)

src/backend/catalog/pg_constraint.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.48 2009/10/12 19:49:24 adunstan Exp $
11+
* $PostgreSQL: pgsql/src/backend/catalog/pg_constraint.c,v 1.49 2009/10/13 00:53:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -705,7 +705,8 @@ AlterConstraintNamespaces(Oid ownerId, Oid oldNspId,
705705

706706
/*
707707
* GetConstraintByName
708-
* Find a constraint with the specified name.
708+
* Find a constraint on the specified relation with the specified name.
709+
* Returns constraint's OID.
709710
*/
710711
Oid
711712
GetConstraintByName(Oid relid, const char *conname)
@@ -725,7 +726,8 @@ GetConstraintByName(Oid relid, const char *conname)
725726

726727
ScanKeyInit(&skey[0],
727728
Anum_pg_constraint_conrelid,
728-
BTEqualStrategyNumber, F_OIDEQ, relid);
729+
BTEqualStrategyNumber, F_OIDEQ,
730+
ObjectIdGetDatum(relid));
729731

730732
scan = systable_beginscan(pg_constraint, ConstraintRelidIndexId, true,
731733
SnapshotNow, 1, skey);
@@ -737,28 +739,22 @@ GetConstraintByName(Oid relid, const char *conname)
737739
if (strcmp(NameStr(con->conname), conname) == 0)
738740
{
739741
if (OidIsValid(conOid))
740-
{
741-
char *relname = get_rel_name(relid);
742742
ereport(ERROR,
743743
(errcode(ERRCODE_DUPLICATE_OBJECT),
744-
errmsg("table \"%s\" has multiple constraints named \"%s\"",
745-
(relname ? relname : "(unknown)"), conname)));
746-
}
744+
errmsg("table \"%s\" has multiple constraints named \"%s\"",
745+
get_rel_name(relid), conname)));
747746
conOid = HeapTupleGetOid(tuple);
748747
}
749748
}
750749

751750
systable_endscan(scan);
752751

753-
/* If no constraint exists for the relation specified, notify user */
752+
/* If no such constraint exists, complain */
754753
if (!OidIsValid(conOid))
755-
{
756-
char *relname = get_rel_name(relid);
757754
ereport(ERROR,
758755
(errcode(ERRCODE_UNDEFINED_OBJECT),
759756
errmsg("constraint \"%s\" for table \"%s\" does not exist",
760-
conname, (relname ? relname : "(unknown)"))));
761-
}
757+
conname, get_rel_name(relid))));
762758

763759
heap_close(pg_constraint, AccessShareLock);
764760

src/backend/commands/sequence.c

Lines changed: 2 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/sequence.c,v 1.161 2009/07/16 06:33:42 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/sequence.c,v 1.162 2009/10/13 00:53:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -132,6 +132,7 @@ DefineSequence(CreateSeqStmt *seq)
132132
coldef->inhcount = 0;
133133
coldef->is_local = true;
134134
coldef->is_not_null = true;
135+
coldef->storage = 0;
135136
coldef->raw_default = NULL;
136137
coldef->cooked_default = NULL;
137138
coldef->constraints = NIL;

src/backend/commands/tablecmds.c

Lines changed: 20 additions & 29 deletions
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.302 2009/10/12 19:49:24 adunstan Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/tablecmds.c,v 1.303 2009/10/13 00:53:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -333,7 +333,7 @@ static void ATExecAddInherit(Relation rel, RangeVar *parent);
333333
static void ATExecDropInherit(Relation rel, RangeVar *parent);
334334
static void copy_relation_data(SMgrRelation rel, SMgrRelation dst,
335335
ForkNumber forkNum, bool istemp);
336-
static const char * storage_name(char c);
336+
static const char *storage_name(char c);
337337

338338

339339
/* ----------------------------------------------------------------
@@ -1102,22 +1102,25 @@ truncate_check_rel(Relation rel)
11021102
CheckTableNotInUse(rel, "TRUNCATE");
11031103
}
11041104

1105-
1106-
/*----------------
1105+
/*
11071106
* storage_name
1108-
* returns a name corresponding to a storage enum value
1109-
* For use in error messages
1107+
* returns the name corresponding to a typstorage/attstorage enum value
11101108
*/
11111109
static const char *
11121110
storage_name(char c)
11131111
{
11141112
switch (c)
11151113
{
1116-
case 'p': return "PLAIN";
1117-
case 'm': return "MAIN";
1118-
case 'x': return "EXTENDED";
1119-
case 'e': return "EXTERNAL";
1120-
default: return "???";
1114+
case 'p':
1115+
return "PLAIN";
1116+
case 'm':
1117+
return "MAIN";
1118+
case 'x':
1119+
return "EXTENDED";
1120+
case 'e':
1121+
return "EXTERNAL";
1122+
default:
1123+
return "???";
11211124
}
11221125
}
11231126

@@ -1189,7 +1192,6 @@ MergeAttributes(List *schema, List *supers, bool istemp,
11891192
List *constraints = NIL;
11901193
int parentsWithOids = 0;
11911194
bool have_bogus_defaults = false;
1192-
bool have_bogus_comments = false;
11931195
int child_attno;
11941196
static Node bogus_marker = { 0 }; /* marks conflicting defaults */
11951197

@@ -1354,7 +1356,8 @@ MergeAttributes(List *schema, List *supers, bool istemp,
13541356
(errcode(ERRCODE_DATATYPE_MISMATCH),
13551357
errmsg("inherited column \"%s\" has a storage parameter conflict",
13561358
attributeName),
1357-
errdetail("%s versus %s", storage_name(def->storage),
1359+
errdetail("%s versus %s",
1360+
storage_name(def->storage),
13581361
storage_name(attribute->attstorage))));
13591362

13601363
def->inhcount++;
@@ -1375,10 +1378,10 @@ MergeAttributes(List *schema, List *supers, bool istemp,
13751378
def->inhcount = 1;
13761379
def->is_local = false;
13771380
def->is_not_null = attribute->attnotnull;
1381+
def->storage = attribute->attstorage;
13781382
def->raw_default = NULL;
13791383
def->cooked_default = NULL;
13801384
def->constraints = NIL;
1381-
def->storage = attribute->attstorage;
13821385
inhSchema = lappend(inhSchema, def);
13831386
newattno[parent_attno - 1] = ++child_attno;
13841387
}
@@ -1525,7 +1528,8 @@ MergeAttributes(List *schema, List *supers, bool istemp,
15251528
(errcode(ERRCODE_DATATYPE_MISMATCH),
15261529
errmsg("column \"%s\" has a storage parameter conflict",
15271530
attributeName),
1528-
errdetail("%s versus %s", storage_name(def->storage),
1531+
errdetail("%s versus %s",
1532+
storage_name(def->storage),
15291533
storage_name(newdef->storage))));
15301534

15311535
/* Mark the column as locally defined */
@@ -1580,20 +1584,6 @@ MergeAttributes(List *schema, List *supers, bool istemp,
15801584
}
15811585
}
15821586

1583-
/* Raise an error if we found conflicting comments. */
1584-
if (have_bogus_comments)
1585-
{
1586-
foreach(entry, schema)
1587-
{
1588-
ColumnDef *def = lfirst(entry);
1589-
1590-
if (def->cooked_default == &bogus_marker)
1591-
ereport(ERROR,
1592-
(errcode(ERRCODE_INVALID_COLUMN_DEFINITION),
1593-
errmsg("column \"%s\" inherits conflicting comments", def->colname)));
1594-
}
1595-
}
1596-
15971587
*supOids = parentOids;
15981588
*supconstr = constraints;
15991589
*supOidCount = parentsWithOids;
@@ -3903,6 +3893,7 @@ ATPrepAddOids(List **wqueue, Relation rel, bool recurse, AlterTableCmd *cmd)
39033893
cdef->inhcount = 0;
39043894
cdef->is_local = true;
39053895
cdef->is_not_null = true;
3896+
cdef->storage = 0;
39063897
cmd->def = (Node *) cdef;
39073898
}
39083899
ATPrepAddColumn(wqueue, rel, recurse, cmd);

src/backend/commands/view.c

Lines changed: 2 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/view.c,v 1.117 2009/07/16 06:33:42 petere Exp $
11+
* $PostgreSQL: pgsql/src/backend/commands/view.c,v 1.118 2009/10/13 00:53:07 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -124,6 +124,7 @@ DefineVirtualRelation(const RangeVar *relation, List *tlist, bool replace)
124124
def->inhcount = 0;
125125
def->is_local = true;
126126
def->is_not_null = false;
127+
def->storage = 0;
127128
def->raw_default = NULL;
128129
def->cooked_default = NULL;
129130
def->constraints = NIL;

src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Portions Copyright (c) 1994, Regents of the University of California
1616
*
1717
* IDENTIFICATION
18-
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.446 2009/10/12 20:39:39 tgl Exp $
18+
* $PostgreSQL: pgsql/src/backend/nodes/copyfuncs.c,v 1.447 2009/10/13 00:53:08 tgl Exp $
1919
*
2020
*-------------------------------------------------------------------------
2121
*/
@@ -2115,6 +2115,7 @@ _copyColumnDef(ColumnDef *from)
21152115
COPY_SCALAR_FIELD(inhcount);
21162116
COPY_SCALAR_FIELD(is_local);
21172117
COPY_SCALAR_FIELD(is_not_null);
2118+
COPY_SCALAR_FIELD(storage);
21182119
COPY_NODE_FIELD(raw_default);
21192120
COPY_NODE_FIELD(cooked_default);
21202121
COPY_NODE_FIELD(constraints);

src/backend/nodes/equalfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Portions Copyright (c) 1994, Regents of the University of California
2323
*
2424
* IDENTIFICATION
25-
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.368 2009/10/12 20:39:40 tgl Exp $
25+
* $PostgreSQL: pgsql/src/backend/nodes/equalfuncs.c,v 1.369 2009/10/13 00:53:08 tgl Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -2084,6 +2084,7 @@ _equalColumnDef(ColumnDef *a, ColumnDef *b)
20842084
COMPARE_SCALAR_FIELD(inhcount);
20852085
COMPARE_SCALAR_FIELD(is_local);
20862086
COMPARE_SCALAR_FIELD(is_not_null);
2087+
COMPARE_SCALAR_FIELD(storage);
20872088
COMPARE_NODE_FIELD(raw_default);
20882089
COMPARE_NODE_FIELD(cooked_default);
20892090
COMPARE_NODE_FIELD(constraints);

src/backend/nodes/outfuncs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.368 2009/10/12 18:10:45 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/nodes/outfuncs.c,v 1.369 2009/10/13 00:53:08 tgl Exp $
1212
*
1313
* NOTES
1414
* Every node type that can appear in stored rules' parsetrees *must*
@@ -1885,6 +1885,7 @@ _outColumnDef(StringInfo str, ColumnDef *node)
18851885
WRITE_INT_FIELD(inhcount);
18861886
WRITE_BOOL_FIELD(is_local);
18871887
WRITE_BOOL_FIELD(is_not_null);
1888+
WRITE_INT_FIELD(storage);
18881889
WRITE_NODE_FIELD(raw_default);
18891890
WRITE_NODE_FIELD(cooked_default);
18901891
WRITE_NODE_FIELD(constraints);

0 commit comments

Comments
 (0)