Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc65ea0e

Browse files
committed
New pg_attribute.atttypmod for type-specific information like
varchar length.Cleans up code so attlen is always length.Removed varchar() hack added earlier.Will fix bug in selecting varchar() fields, and varchar() can bevariable length.
1 parentd7427e4 commitc65ea0e

File tree

27 files changed

+339
-467
lines changed

27 files changed

+339
-467
lines changed

‎src/backend/access/common/tupdesc.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.31 1998/01/07 21:00:45 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.32 1998/01/16 23:19:16 momjian Exp $
1111
*
1212
* NOTES
1313
* some of the executor utility code such as "ExecTypeFromTL" should be
@@ -301,11 +301,12 @@ TupleDescInitEntry(TupleDesc desc,
301301

302302
att->attdisbursion=0;/* dummy value */
303303
att->attcacheoff=-1;
304+
att->atttypmod=0;
304305

305306
att->attnum=attributeNumber;
306307
att->attnelems=attdim;
307308
att->attisset=attisset;
308-
309+
309310
att->attnotnull= false;
310311
att->atthasdef= false;
311312

@@ -512,17 +513,7 @@ BuildDescForRelation(List *schema, char *relname)
512513
typename);
513514
}
514515

515-
/*
516-
* this is for char() and varchar(). When an entry is of type
517-
* char() or varchar(), typlen is set to the appropriate length,
518-
* which we'll use here instead. (The catalog lookup only returns
519-
* the length of bpchar and varchar which is not what we want!) -
520-
* ay 6/95
521-
*/
522-
if (entry->typename->typlen>0)
523-
{
524-
desc->attrs[attnum-1]->attlen=entry->typename->typlen;
525-
}
516+
desc->attrs[attnum-1]->atttypmod=entry->typename->typmod;
526517

527518
/* This is for constraints */
528519
if (entry->is_not_null)

‎src/backend/catalog/catalog.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.12 1998/01/0619:42:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/catalog.c,v 1.13 1998/01/16 23:19:23 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -190,16 +190,9 @@ fillatt(TupleDesc tupleDesc)
190190
* and byval, since those were already set in
191191
* TupleDescInitEntry.In fact, this seems redundant here,
192192
* but who knows what I'll break if I take it out...
193-
*
194-
* same for char() and varchar() stuff. I share the same
195-
* sentiments. This function is poorly written anyway. -ay
196-
* 6/95
197193
*/
198-
if (!(*attributeP)->attisset&&
199-
(*attributeP)->atttypid!=BPCHAROID&&
200-
(*attributeP)->atttypid!=VARCHAROID)
194+
if (!(*attributeP)->attisset)
201195
{
202-
203196
typp= (TypeTupleForm)GETSTRUCT(tuple);/* XXX */
204197
(*attributeP)->attlen=typp->typlen;
205198
(*attributeP)->attbyval=typp->typbyval;

‎src/backend/catalog/index.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.35 1998/01/1519:42:27pgsql Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/catalog/index.c,v 1.36 1998/01/16 23:19:27momjian Exp $
1111
*
1212
*
1313
* INTERFACE ROUTINES
@@ -107,6 +107,7 @@ DefaultBuild(Relation heapRelation, Relation indexRelation,
107107
*AttrNumberattnum;
108108
*uint32attnelems;
109109
*int32attcacheoff;
110+
*int16atttypmod;
110111
*boolattbyval;
111112
*boolattisset;
112113
*charattalign;
@@ -117,12 +118,12 @@ DefaultBuild(Relation heapRelation, Relation indexRelation,
117118
* ----------------------------------------------------------------
118119
*/
119120
staticFormData_pg_attributesysatts[]= {
120-
{0l, {"ctid"},27l,0l,6,-1,0,-1,'\0','\0','i','\0','\0'},
121-
{0l, {"oid"},26l,0l,4,-2,0,-1,'\001','\0','i','\0','\0'},
122-
{0l, {"xmin"},28l,0l,4,-3,0,-1,'\0','\0','i','\0','\0'},
123-
{0l, {"cmin"},29l,0l,4,-4,0,-1,'\001','\0','i','\0','\0'},
124-
{0l, {"xmax"},28l,0l,4,-5,0,-1,'\0','\0','i','\0','\0'},
125-
{0l, {"cmax"},29l,0l,4,-6,0,-1,'\001','\0','i','\0','\0'},
121+
{0l, {"ctid"},27l,0l,6,-1,0,-1,0,'\0','\0','i','\0','\0'},
122+
{0l, {"oid"},26l,0l,4,-2,0,-1,0,'\001','\0','i','\0','\0'},
123+
{0l, {"xmin"},28l,0l,4,-3,0,-1,0,'\0','\0','i','\0','\0'},
124+
{0l, {"cmin"},29l,0l,4,-4,0,-1,0,'\001','\0','i','\0','\0'},
125+
{0l, {"xmax"},28l,0l,4,-5,0,-1,0,'\0','\0','i','\0','\0'},
126+
{0l, {"cmax"},29l,0l,4,-6,0,-1,0,'\001','\0','i','\0','\0'},
126127
};
127128

128129
/* ----------------------------------------------------------------
@@ -436,6 +437,7 @@ ConstructTupleDescriptor(Oid heapoid,
436437

437438
((AttributeTupleForm)to)->attnotnull= false;
438439
((AttributeTupleForm)to)->atthasdef= false;
440+
((AttributeTupleForm)to)->atttypmod=0;
439441

440442
/*
441443
* if the keytype is defined, we need to change the tuple form's
@@ -454,11 +456,11 @@ ConstructTupleDescriptor(Oid heapoid,
454456
((AttributeTupleForm)to)->atttypid=tup->t_oid;
455457
((AttributeTupleForm)to)->attbyval=
456458
((TypeTupleForm) ((char*)tup+tup->t_hoff))->typbyval;
457-
if (IndexKeyType->typlen>0)
458-
((AttributeTupleForm)to)->attlen=IndexKeyType->typlen;
459-
else
460-
((AttributeTupleForm)to)->attlen=
459+
460+
((AttributeTupleForm)to)->attlen=
461461
((TypeTupleForm) ((char*)tup+tup->t_hoff))->typlen;
462+
463+
((AttributeTupleForm)to)->atttypmod=IndexKeyType->typmod;
462464
}
463465

464466

‎src/backend/commands/command.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.23 1998/01/05 16:38:44 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.24 1998/01/16 23:19:33 momjian Exp $
1111
*
1212
* NOTES
1313
* The PortalExecutorHeapMemory crap needs to be eliminated
@@ -482,11 +482,8 @@ PerformAddAttribute(char *relationName,
482482
}
483483
namestrcpy(&(attribute->attname), (char*)key[1].sk_argument);
484484
attribute->atttypid=typeTuple->t_oid;
485-
if (colDef->typename->typlen>0)
486-
attribute->attlen=colDef->typename->typlen;
487-
else
488-
/* bpchar, varchar, text */
489-
attribute->attlen=form->typlen;
485+
attribute->attlen=form->typlen;
486+
attribute->atttypmod=colDef->typename->typmod;
490487
attribute->attnum=i;
491488
attribute->attbyval=form->typbyval;
492489
attribute->attnelems=attnelems;

‎src/backend/commands/copy.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
*
88
* IDENTIFICATION
9-
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.38 1998/01/1519:42:36 pgsql Exp $
9+
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.39 1998/01/16 23:19:40 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -574,7 +574,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
574574
values[i]=
575575
(Datum) (*fmgr_faddr(&in_functions[i])) (string,
576576
elements[i],
577-
attr[i]->attlen);
577+
attr[i]->atttypmod);
578578

579579
/*
580580
* Sanity check - by reference attributes cannot

‎src/backend/commands/sequence.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ DefineSequence(CreateSeqStmt *seq)
9898
typnam=makeNode(TypeName);
9999
typnam->setof= FALSE;
100100
typnam->arrayBounds=NULL;
101+
typnam->typmod=0;
101102
coldef=makeNode(ColumnDef);
102103
coldef->typename=typnam;
103104
coldef->defval=NULL;

‎src/backend/executor/execAmi.c

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.15 1998/01/1605:03:45 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/execAmi.c,v 1.16 1998/01/1623:19:47 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -42,7 +42,6 @@
4242
#include"access/genam.h"
4343
#include"access/heapam.h"
4444
#include"catalog/heap.h"
45-
#include"catalog/pg_type.h"
4645

4746
staticPointer
4847
ExecBeginScan(Relationrelation,intnkeys,ScanKeyskeys,
@@ -125,31 +124,6 @@ ExecOpenR(Oid relationOid, bool isindex)
125124
if (relation==NULL)
126125
elog(DEBUG,"ExecOpenR: relation == NULL, heap_open failed.");
127126

128-
{
129-
inti;
130-
Relationtrel=palloc(sizeof(RelationData));
131-
TupleDesctdesc=palloc(sizeof(structtupleDesc));
132-
AttributeTupleForm*tatt=
133-
palloc(sizeof(AttributeTupleForm*)*relation->rd_att->natts);
134-
135-
memcpy(trel,relation,sizeof(RelationData));
136-
memcpy(tdesc,relation->rd_att,sizeof(structtupleDesc));
137-
trel->rd_att=tdesc;
138-
tdesc->attrs=tatt;
139-
140-
for (i=0;i<relation->rd_att->natts;i++)
141-
{
142-
if (relation->rd_att->attrs[i]->atttypid!=VARCHAROID)
143-
tdesc->attrs[i]=relation->rd_att->attrs[i];
144-
else
145-
{
146-
tdesc->attrs[i]=palloc(sizeof(FormData_pg_attribute));
147-
memcpy(tdesc->attrs[i],relation->rd_att->attrs[i],
148-
sizeof(FormData_pg_attribute));
149-
tdesc->attrs[i]->attlen=-1;
150-
}
151-
}
152-
}
153127
returnrelation;
154128
}
155129

‎src/backend/executor/execMain.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
*
2828
* IDENTIFICATION
29-
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.38 1998/01/14 15:48:09 momjian Exp $
29+
* $Header: /cvsroot/pgsql/src/backend/executor/execMain.c,v 1.39 1998/01/16 23:19:49 momjian Exp $
3030
*
3131
*-------------------------------------------------------------------------
3232
*/
@@ -563,13 +563,8 @@ InitPlan(CmdType operation, Query *parseTree, Plan *plan, EState *estate)
563563
*/
564564
tupdesc=CreateTupleDescCopy(tupType);
565565

566-
/* fixup to prevent zero-length columns in create */
567-
setVarAttrLenForCreateTable(tupdesc,targetList,rangeTable);
568-
569566
intoRelationId=heap_create_with_catalog(intoName,tupdesc);
570-
#ifdefNOT_USED/* it's copy ... */
571-
resetVarAttrLenForCreateTable(tupdesc);
572-
#endif
567+
573568
FreeTupleDesc(tupdesc);
574569

575570
/* ----------------

‎src/backend/executor/execUtils.c

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.23 1998/01/07 21:02:50 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/executor/execUtils.c,v 1.24 1998/01/16 23:19:52 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1177,76 +1177,3 @@ ExecInsertIndexTuples(TupleTableSlot *slot,
11771177
if (econtext!=NULL)
11781178
pfree(econtext);
11791179
}
1180-
1181-
/* ----------------------------------------------------------------
1182-
* setVarAttrLenForCreateTable -
1183-
* called when we do a SELECT * INTO TABLE tab
1184-
* needed for attributes that have a defined length, like bpchar and
1185-
* varchar
1186-
* ----------------------------------------------------------------
1187-
*/
1188-
void
1189-
setVarAttrLenForCreateTable(TupleDesctupType,List*targetList,
1190-
List*rangeTable)
1191-
{
1192-
List*tl;
1193-
TargetEntry*tle;
1194-
Node*expr;
1195-
intvarno;
1196-
1197-
tl=targetList;
1198-
1199-
for (varno=0;varno<tupType->natts;varno++)
1200-
{
1201-
tle=lfirst(tl);
1202-
1203-
if (tupType->attrs[varno]->atttypid==BPCHAROID||
1204-
tupType->attrs[varno]->atttypid==VARCHAROID)
1205-
{
1206-
expr=tle->expr;
1207-
if (expr&&IsA(expr,Var))
1208-
{
1209-
Var*var;
1210-
RangeTblEntry*rtentry;
1211-
Relationrd;
1212-
1213-
var= (Var*)expr;
1214-
rtentry=rt_fetch(var->varnoold,rangeTable);
1215-
rd=heap_open(rtentry->relid);
1216-
/* set length to that defined in relation */
1217-
tupType->attrs[varno]->attlen=
1218-
(*rd->rd_att->attrs[var->varoattno-1]).attlen;
1219-
heap_close(rd);
1220-
}
1221-
else
1222-
elog(ERROR,"setVarAttrLenForCreateTable: can't get length for variable-length field");
1223-
}
1224-
tl=lnext(tl);
1225-
}
1226-
}
1227-
1228-
1229-
#ifdefNOT_USED/* look at execMain.c */
1230-
/* ----------------------------------------------------------------
1231-
* resetVarAttrLenForCreateTable -
1232-
* called when we do a SELECT * INTO TABLE tab
1233-
* needed for attributes that have a defined length, like bpchar and
1234-
* varchar
1235-
* resets length to -1 for those types
1236-
* ----------------------------------------------------------------
1237-
*/
1238-
void
1239-
resetVarAttrLenForCreateTable(TupleDesctupType)
1240-
{
1241-
intvarno;
1242-
1243-
for (varno=0;varno<tupType->natts;varno++)
1244-
{
1245-
if (tupType->attrs[varno]->atttypid==BPCHAROID||
1246-
tupType->attrs[varno]->atttypid==VARCHAROID)
1247-
/* set length to original -1 */
1248-
tupType->attrs[varno]->attlen=-1;
1249-
}
1250-
}
1251-
1252-
#endif

‎src/backend/nodes/copyfuncs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.30 1998/01/15 18:59:20 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.31 1998/01/16 23:19:56 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1480,8 +1480,8 @@ _copyTypeName(TypeName *from)
14801480
newnode->name=pstrdup(from->name);
14811481
newnode->timezone=from->timezone;
14821482
newnode->setof=from->setof;
1483+
newnode->typmod=from->typmod;
14831484
Node_Copy(from,newnode,arrayBounds);
1484-
newnode->typlen=from->typlen;
14851485

14861486
returnnewnode;
14871487
}

‎src/backend/nodes/outfuncs.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.21 1998/01/15 18:59:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.22 1998/01/16 23:19:59 momjian Exp $
1111
*
1212
* NOTES
1313
* Every (plan) node in POSTGRES has an associated "out" routine which
@@ -137,11 +137,11 @@ _outTypeName(StringInfo str, TypeName *node)
137137
appendStringInfo(str, (node->timezone ?"true" :"false"));
138138
appendStringInfo(str," :setof ");
139139
appendStringInfo(str, (node->setof ?"true" :"false"));
140+
appendStringInfo(str," :typmod ");
141+
sprintf(buf," %d ",node->typmod);
142+
appendStringInfo(str,buf);
140143
appendStringInfo(str," :arrayBounds ");
141144
_outNode(str,node->arrayBounds);
142-
appendStringInfo(str," :typlen ");
143-
sprintf(buf," %d ",node->typlen);
144-
appendStringInfo(str,buf);
145145
}
146146

147147
staticvoid

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp