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

Commitcfd9be9

Browse files
committed
Change the UNKNOWN type to have an internal representation matching
cstring, rather than text, so as to eliminate useless conversionsinside the parser. Per recent discussion.
1 parentc8f81df commitcfd9be9

File tree

5 files changed

+37
-47
lines changed

5 files changed

+37
-47
lines changed

‎src/backend/parser/parse_coerce.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.129 2005/05/29 18:24:13 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_coerce.c,v 2.130 2005/05/30 01:20:49 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -168,8 +168,11 @@ coerce_type(ParseState *pstate, Node *node,
168168

169169
if (!con->constisnull)
170170
{
171-
char*val=DatumGetCString(DirectFunctionCall1(unknownout,
172-
con->constvalue));
171+
/*
172+
* We assume here that UNKNOWN's internal representation is the
173+
* same as CSTRING
174+
*/
175+
char*val=DatumGetCString(con->constvalue);
173176

174177
/*
175178
* We pass typmod -1 to the input routine, primarily because
@@ -183,7 +186,6 @@ coerce_type(ParseState *pstate, Node *node,
183186
* ugly...
184187
*/
185188
newcon->constvalue=stringTypeDatum(targetType,val,-1);
186-
pfree(val);
187189
}
188190

189191
result= (Node*)newcon;

‎src/backend/parser/parse_node.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.88 2005/04/23 18:35:12 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/parser/parse_node.c,v 1.89 2005/05/30 01:20:49 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -271,8 +271,8 @@ transformArraySubscripts(ParseState *pstate,
271271
*have to guess what type is wanted.
272272
*
273273
*For string literals we produce a constant of type UNKNOWN ---- whose
274-
*representation is the same astext, but it indicates to later type
275-
*resolution that we're not surethatit should be considered text.
274+
*representation is the same ascstring, but it indicates to later type
275+
*resolution that we're not sureyet what typeit should be considered.
276276
*Explicit "NULL" constants are also typed as UNKNOWN.
277277
*
278278
*For integers and floats we produce int4, int8, or numeric depending
@@ -341,11 +341,14 @@ make_const(Value *value)
341341
break;
342342

343343
caseT_String:
344-
val=DirectFunctionCall1(unknownin,
345-
CStringGetDatum(strVal(value)));
344+
/*
345+
* We assume here that UNKNOWN's internal representation is the
346+
* same as CSTRING
347+
*/
348+
val=CStringGetDatum(strVal(value));
346349

347350
typeid=UNKNOWNOID;/* will be coerced later */
348-
typelen=-1;/*variable len */
351+
typelen=-2;/*cstring-style varwidth type */
349352
typebyval= false;
350353
break;
351354

@@ -362,7 +365,7 @@ make_const(Value *value)
362365
caseT_Null:
363366
/* return a null const */
364367
con=makeConst(UNKNOWNOID,
365-
-1,
368+
-2,
366369
(Datum)0,
367370
true,
368371
false);

‎src/backend/utils/adt/varlena.c

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.122 2005/05/27 00:57:49 neilc Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/varlena.c,v 1.123 2005/05/30 01:20:50 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -330,18 +330,10 @@ textsend(PG_FUNCTION_ARGS)
330330
Datum
331331
unknownin(PG_FUNCTION_ARGS)
332332
{
333-
char*inputStr=PG_GETARG_CSTRING(0);
334-
unknown*result;
335-
intlen;
336-
337-
len=strlen(inputStr)+VARHDRSZ;
338-
339-
result= (unknown*)palloc(len);
340-
VARATT_SIZEP(result)=len;
341-
342-
memcpy(VARDATA(result),inputStr,len-VARHDRSZ);
333+
char*str=PG_GETARG_CSTRING(0);
343334

344-
PG_RETURN_UNKNOWN_P(result);
335+
/* representation is same as cstring */
336+
PG_RETURN_CSTRING(pstrdup(str));
345337
}
346338

347339
/*
@@ -350,16 +342,10 @@ unknownin(PG_FUNCTION_ARGS)
350342
Datum
351343
unknownout(PG_FUNCTION_ARGS)
352344
{
353-
unknown*t=PG_GETARG_UNKNOWN_P(0);
354-
intlen;
355-
char*result;
356-
357-
len=VARSIZE(t)-VARHDRSZ;
358-
result= (char*)palloc(len+1);
359-
memcpy(result,VARDATA(t),len);
360-
result[len]='\0';
345+
/* representation is same as cstring */
346+
char*str=PG_GETARG_CSTRING(0);
361347

362-
PG_RETURN_CSTRING(result);
348+
PG_RETURN_CSTRING(pstrdup(str));
363349
}
364350

365351
/*
@@ -369,28 +355,27 @@ Datum
369355
unknownrecv(PG_FUNCTION_ARGS)
370356
{
371357
StringInfobuf= (StringInfo)PG_GETARG_POINTER(0);
372-
unknown*result;
358+
char*str;
373359
intnbytes;
374360

375-
nbytes=buf->len-buf->cursor;
376-
result= (unknown*)palloc(nbytes+VARHDRSZ);
377-
VARATT_SIZEP(result)=nbytes+VARHDRSZ;
378-
pq_copymsgbytes(buf,VARDATA(result),nbytes);
379-
PG_RETURN_UNKNOWN_P(result);
361+
str=pq_getmsgtext(buf,buf->len-buf->cursor,&nbytes);
362+
/* representation is same as cstring */
363+
PG_RETURN_CSTRING(str);
380364
}
381365

382366
/*
383367
*unknownsend- converts unknown to binary format
384-
*
385-
* This is a special case: just copy the input, since it's
386-
* effectively the same format as bytea
387368
*/
388369
Datum
389370
unknownsend(PG_FUNCTION_ARGS)
390371
{
391-
unknown*vlena=PG_GETARG_UNKNOWN_P_COPY(0);
372+
/* representation is same as cstring */
373+
char*str=PG_GETARG_CSTRING(0);
374+
StringInfoDatabuf;
392375

393-
PG_RETURN_UNKNOWN_P(vlena);
376+
pq_begintypsend(&buf);
377+
pq_sendtext(&buf,str,strlen(str));
378+
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
394379
}
395380

396381

‎src/include/catalog/catversion.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
40-
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.269 2005/05/20 01:29:55 neilc Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.270 2005/05/30 01:20:50 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200505201
56+
#defineCATALOG_VERSION_NO200505291
5757

5858
#endif

‎src/include/catalog/pg_type.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.160 2005/04/14 01:38:21 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.161 2005/05/30 01:20:50 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -370,7 +370,7 @@ DESCR("relative, limited-range time interval (Unix delta time)");
370370
DATA(insertOID=704 (tintervalPGNSPPGUID12fbt \05400tintervalintintervalouttintervalrecvtintervalsend-ipf0-10_null__null_ ));
371371
DESCR("(abstime,abstime), time interval");
372372
#defineTINTERVALOID704
373-
DATA(insertOID=705 (unknownPGNSPPGUID-1fbt \05400unknowninunknownoutunknownrecvunknownsend-ipf0-10_null__null_ ));
373+
DATA(insertOID=705 (unknownPGNSPPGUID-2fbt \05400unknowninunknownoutunknownrecvunknownsend-cpf0-10_null__null_ ));
374374
DESCR("");
375375
#defineUNKNOWNOID705
376376

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp