|
8 | 8 | * Portions Copyright (c) 1994, Regents of the University of California
|
9 | 9 | *
|
10 | 10 | * IDENTIFICATION
|
11 |
| - * $PostgreSQL: pgsql/src/backend/access/gin/ginbulk.c,v 1.3 2006/07/14 14:52:16 momjian Exp $ |
| 11 | + * $PostgreSQL: pgsql/src/backend/access/gin/ginbulk.c,v 1.4 2006/07/16 00:54:22 tgl Exp $ |
12 | 12 | *-------------------------------------------------------------------------
|
13 | 13 | */
|
14 | 14 |
|
15 | 15 | #include "postgres.h"
|
| 16 | + |
16 | 17 | #include "access/gin.h"
|
| 18 | +#include "utils/datum.h" |
| 19 | + |
17 | 20 |
|
18 | 21 | #define DEF_NENTRY 2048
|
19 | 22 | #define DEF_NPTR 4
|
@@ -66,37 +69,31 @@ ginInsertData(BuildAccumulator *accum, EntryAccumulator *entry, ItemPointer heap
|
66 | 69 | entry->number++;
|
67 | 70 | }
|
68 | 71 |
|
| 72 | +/* |
| 73 | + * This is basically the same as datumCopy(), but we duplicate some code |
| 74 | + * to avoid computing the datum size twice. |
| 75 | + */ |
69 | 76 | static Datum
|
70 | 77 | getDatumCopy(BuildAccumulator *accum, Datum value) {
|
71 | 78 | Form_pg_attribute *att = accum->ginstate->tupdesc->attrs;
|
72 |
| - Datum newvalue; |
73 |
| - int data_length = 0; |
74 |
| - void *ptr; |
| 79 | + Datum res; |
75 | 80 |
|
76 |
| - if ( att[0]->attbyval ) { |
77 |
| - store_att_byval(&newvalue, value, att[0]->attlen); |
78 |
| - } else { |
79 |
| - /* pass-by-reference */ |
80 |
| - if (att[0]->attlen == -1) { |
81 |
| - /* varlena */ |
82 |
| - data_length = VARATT_SIZE(DatumGetPointer(value)); |
83 |
| - } else if (att[0]->attlen == -2) { |
84 |
| - /* c-string */ |
85 |
| - data_length = strlen(DatumGetCString(value)) + 1; |
86 |
| - } else { |
87 |
| - /* fixed-length pass-by-reference */ |
88 |
| - Assert(att[0]->attlen > 0); |
89 |
| - data_length = att[0]->attlen; |
90 |
| - } |
| 81 | + if (att[0]->attbyval) |
| 82 | + res = value; |
| 83 | + else |
| 84 | + { |
| 85 | + Size realSize; |
| 86 | + char *s; |
91 | 87 |
|
92 |
| - ptr = palloc( data_length ); |
93 |
| - memcpy(ptr, DatumGetPointer(value), data_length); |
94 |
| - newvalue = PointerGetDatum(ptr); |
95 |
| - } |
| 88 | + realSize = datumGetSize(value, false, att[0]->attlen); |
96 | 89 |
|
97 |
| - accum->allocatedMemory+=data_length; |
| 90 | + s = (char *) palloc(realSize); |
| 91 | + memcpy(s, DatumGetPointer(value), realSize); |
| 92 | + res = PointerGetDatum(s); |
98 | 93 |
|
99 |
| - return newvalue; |
| 94 | + accum->allocatedMemory += realSize; |
| 95 | + } |
| 96 | + return res; |
100 | 97 | }
|
101 | 98 |
|
102 | 99 | /*
|
|
0 commit comments