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

Commit5f6f840

Browse files
committed
Reduce the alignment requirement of type "name" from int to char, and arrange
to suppress zero-padding of "name" entries in indexes.The alignment change is unlikely to save any space, but it is really neededanyway to make the world safe for our widespread practice of passing plainold C strings to functions that are declared as taking Name. In the previouscoding, the C compiler was entitled to assume that a Name pointer wasword-aligned; but we were failing to guarantee that. I think the reasonwe'd not seen failures is that usually the only thing that gets done withsuch a pointer is strcmp(), which is hard to optimize in a way that exploitsword-alignment. Still, some enterprising compiler guy will probably thinkof a way eventually, or we might change our code in a way that exposesmore-obvious optimization opportunities.The padding change is accomplished in one-liner fashion by declaring the"name" index opclasses to use storage type "cstring" in pg_opclass.h.Normally btree and hash don't allow a nondefault storage type, because theydon't have any provisions for converting the input datum to another type.However, because name and cstring are effectively the same thing except forpadding, no conversion is needed --- we only need index_form_tuple() to treatthe datum as being cstring not name, and this is sufficient. This seems tomake for about a one-third reduction in the typical sizes of system catalogindexes that involve "name" columns, of which we have many.These two changes are only weakly related, but the alignment change makesme feel safer that the padding change won't introduce problems, so I'mcommitting them together.
1 parent3dc59be commit5f6f840

File tree

8 files changed

+34
-31
lines changed

8 files changed

+34
-31
lines changed

‎src/backend/bootstrap/bootstrap.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.243 2008/05/12 00:00:46 alvherre Exp $
11+
* $PostgreSQL: pgsql/src/backend/bootstrap/bootstrap.c,v 1.244 2008/06/24 17:58:27 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -125,7 +125,7 @@ static const struct typinfo TypInfo[] = {
125125
F_INT4IN,F_INT4OUT},
126126
{"float4",FLOAT4OID,0,4,FLOAT4PASSBYVAL,'i','p',
127127
F_FLOAT4IN,F_FLOAT4OUT},
128-
{"name",NAMEOID,CHAROID,NAMEDATALEN, false,'i','p',
128+
{"name",NAMEOID,CHAROID,NAMEDATALEN, false,'c','p',
129129
F_NAMEIN,F_NAMEOUT},
130130
{"regclass",REGCLASSOID,0,4, true,'i','p',
131131
F_REGCLASSIN,F_REGCLASSOUT},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/utils/adt/name.c,v 1.62 2008/05/27 00:13:09 tgl Exp $
17+
* $PostgreSQL: pgsql/src/backend/utils/adt/name.c,v 1.63 2008/06/24 17:58:27 tgl Exp $
1818
*
1919
*-------------------------------------------------------------------------
2020
*/
@@ -315,7 +315,7 @@ current_schemas(PG_FUNCTION_ARGS)
315315
NAMEOID,
316316
NAMEDATALEN,/* sizeof(Name) */
317317
false,/* Name is not by-val */
318-
'i');/* alignment of Name */
318+
'c');/* alignment of Name */
319319

320320
PG_RETURN_POINTER(array);
321321
}

‎src/include/c.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
1313
* Portions Copyright (c) 1994, Regents of the University of California
1414
*
15-
* $PostgreSQL: pgsql/src/include/c.h,v 1.227 2008/06/17 16:09:06 momjian Exp $
15+
* $PostgreSQL: pgsql/src/include/c.h,v 1.228 2008/06/24 17:58:27 tgl Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -442,16 +442,12 @@ typedef struct
442442
}oidvector;/* VARIABLE LENGTH STRUCT */
443443

444444
/*
445-
* We want NameData to have length NAMEDATALEN and int alignment,
446-
* because that's how the data type 'name' is defined in pg_type.
447-
* Use a union to make sure the compiler agrees. Note that NAMEDATALEN
448-
* must be a multiple of sizeof(int), else sizeof(NameData) will probably
449-
* not come out equal to NAMEDATALEN.
445+
* Representation of a Name: effectively just a C string, but null-padded to
446+
* exactly NAMEDATALEN bytes. The use of a struct is historical.
450447
*/
451-
typedefunionnameData
448+
typedefstructnameData
452449
{
453450
chardata[NAMEDATALEN];
454-
intalignmentDummy;
455451
}NameData;
456452
typedefNameData*Name;
457453

‎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-2008, 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.463 2008/06/17 19:10:56 tgl Exp $
40+
* $PostgreSQL: pgsql/src/include/catalog/catversion.h,v 1.464 2008/06/24 17:58:27 tgl Exp $
4141
*
4242
*-------------------------------------------------------------------------
4343
*/
@@ -53,6 +53,6 @@
5353
*/
5454

5555
/*yyyymmddN */
56-
#defineCATALOG_VERSION_NO200806171
56+
#defineCATALOG_VERSION_NO200806241
5757

5858
#endif

‎src/include/catalog/pg_attribute.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
99
* Portions Copyright (c) 1994, Regents of the University of California
1010
*
11-
* $PostgreSQL: pgsql/src/include/catalog/pg_attribute.h,v 1.137 2008/04/21 00:26:46 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_attribute.h,v 1.138 2008/06/24 17:58:27 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -217,7 +217,7 @@ typedef FormData_pg_attribute *Form_pg_attribute;
217217
* ----------------
218218
*/
219219
#defineSchema_pg_type \
220-
{ 1247, {"typname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
220+
{ 1247, {"typname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0 }, \
221221
{ 1247, {"typnamespace"}, 26, -1,4,2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
222222
{ 1247, {"typowner"}, 26, -1,4,3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
223223
{ 1247, {"typlen"}, 21, -1,2,4, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
@@ -244,7 +244,7 @@ typedef FormData_pg_attribute *Form_pg_attribute;
244244
{ 1247, {"typdefaultbin"}, 25, -1, -1, 25, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
245245
{ 1247, {"typdefault"}, 25, -1, -1, 26, 0, -1, -1, false, 'x', 'i', false, false, false, true, 0 }
246246

247-
DATA(insert (1247typname19-1NAMEDATALEN10-1-1fpitfft0));
247+
DATA(insert (1247typname19-1NAMEDATALEN10-1-1fpctfft0));
248248
DATA(insert (1247typnamespace26-1420-1-1tpitfft0));
249249
DATA(insert (1247typowner26-1430-1-1tpitfft0));
250250
DATA(insert (1247typlen21-1240-1-1tpstfft0));
@@ -283,7 +283,7 @@ DATA(insert ( 1247 tableoid26 0 4 -7 0 -1 -1 t p i t f f t 0));
283283
* ----------------
284284
*/
285285
#defineSchema_pg_proc \
286-
{ 1255, {"proname"},19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
286+
{ 1255, {"proname"},19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0 }, \
287287
{ 1255, {"pronamespace"},26, -1, 4,2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
288288
{ 1255, {"proowner"},26, -1, 4,3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
289289
{ 1255, {"prolang"},26, -1, 4,4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
@@ -305,7 +305,7 @@ DATA(insert ( 1247 tableoid26 0 4 -7 0 -1 -1 t p i t f f t 0));
305305
{ 1255, {"proconfig"}, 1009, -1, -1, 20, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
306306
{ 1255, {"proacl"}, 1034, -1, -1, 21, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }
307307

308-
DATA(insert (1255proname19-1NAMEDATALEN10-1-1fpitfft0));
308+
DATA(insert (1255proname19-1NAMEDATALEN10-1-1fpctfft0));
309309
DATA(insert (1255pronamespace26-1420-1-1tpitfft0));
310310
DATA(insert (1255proowner26-1430-1-1tpitfft0));
311311
DATA(insert (1255prolang26-1440-1-1tpitfft0));
@@ -340,7 +340,7 @@ DATA(insert ( 1255 tableoid26 0 4 -7 0 -1 -1 t p i t f f t 0));
340340
*/
341341
#defineSchema_pg_attribute \
342342
{ 1249, {"attrelid"}, 26, -1,4,1, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
343-
{ 1249, {"attname"}, 19, -1, NAMEDATALEN,2, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
343+
{ 1249, {"attname"}, 19, -1, NAMEDATALEN,2, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0 }, \
344344
{ 1249, {"atttypid"}, 26, -1,4,3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
345345
{ 1249, {"attstattarget"}, 23, -1,4,4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
346346
{ 1249, {"attlen"}, 21, -1,2,5, 0, -1, -1, true, 'p', 's', true, false, false, true, 0 }, \
@@ -358,7 +358,7 @@ DATA(insert ( 1255 tableoid26 0 4 -7 0 -1 -1 t p i t f f t 0));
358358
{ 1249, {"attinhcount"}, 23, -1,4, 17, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }
359359

360360
DATA(insert (1249attrelid26-1410-1-1tpitfft0));
361-
DATA(insert (1249attname19-1NAMEDATALEN20-1-1fpitfft0));
361+
DATA(insert (1249attname19-1NAMEDATALEN20-1-1fpctfft0));
362362
DATA(insert (1249atttypid26-1430-1-1tpitfft0));
363363
DATA(insert (1249attstattarget23-1440-1-1tpitfft0));
364364
DATA(insert (1249attlen21-1250-1-1tpstfft0));
@@ -387,7 +387,7 @@ DATA(insert ( 1249 tableoid26 0 4 -7 0 -1 -1 t p i t f f t 0));
387387
* ----------------
388388
*/
389389
#defineSchema_pg_class \
390-
{ 1259, {"relname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'i', true, false, false, true, 0 }, \
390+
{ 1259, {"relname"}, 19, -1, NAMEDATALEN, 1, 0, -1, -1, false, 'p', 'c', true, false, false, true, 0 }, \
391391
{ 1259, {"relnamespace"}, 26, -1,4,2, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
392392
{ 1259, {"reltype"}, 26, -1,4,3, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
393393
{ 1259, {"relowner"}, 26, -1,4,4, 0, -1, -1, true, 'p', 'i', true, false, false, true, 0 }, \
@@ -415,7 +415,7 @@ DATA(insert ( 1249 tableoid26 0 4 -7 0 -1 -1 t p i t f f t 0));
415415
{ 1259, {"relacl"}, 1034, -1, -1, 26, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }, \
416416
{ 1259, {"reloptions"}, 1009, -1, -1, 27, 1, -1, -1, false, 'x', 'i', false, false, false, true, 0 }
417417

418-
DATA(insert (1259relname19-1NAMEDATALEN10-1-1fpitfft0));
418+
DATA(insert (1259relname19-1NAMEDATALEN10-1-1fpctfft0));
419419
DATA(insert (1259relnamespace26-1420-1-1tpitfft0));
420420
DATA(insert (1259reltype26-1430-1-1tpitfft0));
421421
DATA(insert (1259relowner26-1440-1-1tpitfft0));

‎src/include/catalog/pg_opclass.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
2929
* Portions Copyright (c) 1994, Regents of the University of California
3030
*
31-
* $PostgreSQL: pgsql/src/include/catalog/pg_opclass.h,v 1.81 2008/05/27 00:13:09 tgl Exp $
31+
* $PostgreSQL: pgsql/src/include/catalog/pg_opclass.h,v 1.82 2008/06/24 17:58:27 tgl Exp $
3232
*
3333
* NOTES
3434
* the genbki.sh script reads this file and generates .bki
@@ -121,8 +121,15 @@ DATA(insert (403interval_opsPGNSP PGUID 1982 1186 t 0 ));
121121
DATA(insert (405interval_opsPGNSPPGUID19831186t0 ));
122122
DATA(insert (403macaddr_opsPGNSPPGUID1984829t0 ));
123123
DATA(insert (405macaddr_opsPGNSPPGUID1985829t0 ));
124-
DATA(insert (403name_opsPGNSPPGUID198619t0 ));
125-
DATA(insert (405name_opsPGNSPPGUID198719t0 ));
124+
/*
125+
* Here's an ugly little hack to save space in the system catalog indexes.
126+
* btree and hash don't ordinarily allow a storage type different from input
127+
* type; but cstring and name are the same thing except for trailing padding,
128+
* and we can safely omit that within an index entry. So we declare the
129+
* opclasses for name as using cstring storage type.
130+
*/
131+
DATA(insert (403name_opsPGNSPPGUID198619t2275 ));
132+
DATA(insert (405name_opsPGNSPPGUID198719t2275 ));
126133
DATA(insert (403numeric_opsPGNSPPGUID19881700t0 ));
127134
DATA(insert (405numeric_opsPGNSPPGUID19981700t0 ));
128135
DATA(insertOID=1981 (403oid_opsPGNSPPGUID198926t0 ));

‎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-2008, 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.195 2008/04/21 00:26:47 tgl Exp $
11+
* $PostgreSQL: pgsql/src/include/catalog/pg_type.h,v 1.196 2008/06/24 17:58:27 tgl Exp $
1212
*
1313
* NOTES
1414
* the genbki.sh script reads this file and generates .bki
@@ -267,7 +267,7 @@ DATA(insert OID = 18 (char PGNSP PGUID1 t b t \054 0 0 1002 charin charout
267267
DESCR("single character");
268268
#defineCHAROID18
269269

270-
DATA(insertOID=19 (namePGNSPPGUIDNAMEDATALENfbt \0540181003nameinnameoutnamerecvnamesend---ipf0-10_null__null_ ));
270+
DATA(insertOID=19 (namePGNSPPGUIDNAMEDATALENfbt \0540181003nameinnameoutnamerecvnamesend---cpf0-10_null__null_ ));
271271
DESCR("63-character type for storing system identifiers");
272272
#defineNAMEOID19
273273

‎src/include/pg_config_manual.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
* for developers.If you edit any of these, be sure to do a *full*
77
* rebuild (and an initdb if noted).
88
*
9-
* $PostgreSQL: pgsql/src/include/pg_config_manual.h,v 1.33 2008/05/02 19:52:37 tgl Exp $
9+
* $PostgreSQL: pgsql/src/include/pg_config_manual.h,v 1.34 2008/06/24 17:58:27 tgl Exp $
1010
*------------------------------------------------------------------------
1111
*/
1212

1313
/*
1414
* Maximum length for identifiers (e.g. table names, column names,
15-
* function names).It must be a multiple of sizeof(int) (typically
16-
*4).
15+
* function names).Names actually are limited to one less byte than this,
16+
*because the length must include a trailing zero byte.
1717
*
1818
* Changing this requires an initdb.
1919
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp