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

Commit93162b5

Browse files
committed
PGPRO-2440: Use destination's context to add into the hash table
1 parent2f955d4 commit93162b5

File tree

3 files changed

+50
-19
lines changed

3 files changed

+50
-19
lines changed

‎pg_variables.c

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,36 +1582,24 @@ createVariableInternal(Package *package, text *name, Oid typid,
15821582
staticvoid
15831583
copyValue(VarState*src,VarState*dest,Variable*destVar)
15841584
{
1585-
MemoryContextoldcxt,
1586-
destctx;
1585+
MemoryContextoldcxt;
15871586

1588-
destctx=destVar->package->hctxTransact;
1589-
oldcxt=MemoryContextSwitchTo(destctx);
1587+
oldcxt=MemoryContextSwitchTo(destVar->package->hctxTransact);
15901588

15911589
if (destVar->typid==RECORDOID)
15921590
/* copy record value */
15931591
{
1594-
boolfound;
1595-
HASH_SEQ_STATUS*rstat;
1596-
HashRecordEntry*item_prev,
1597-
*item_new;
1592+
HASH_SEQ_STATUSrstat;
1593+
HashRecordEntry*item_src;
15981594
RecordVar*record_src=&src->value.record;
15991595
RecordVar*record_dest=&dest->value.record;
16001596

16011597
init_record(record_dest,record_src->tupdesc,destVar);
16021598

16031599
/* Copy previous history entry into the new one */
1604-
rstat= (HASH_SEQ_STATUS*)palloc0(sizeof(HASH_SEQ_STATUS));
1605-
hash_seq_init(rstat,record_src->rhash);
1606-
while ((item_prev= (HashRecordEntry*)hash_seq_search(rstat))!=NULL)
1607-
{
1608-
HashRecordKeyk;
1609-
1610-
k=item_prev->key;
1611-
item_new= (HashRecordEntry*)hash_search(record_dest->rhash,&k,
1612-
HASH_ENTER,&found);
1613-
item_new->tuple=heap_copytuple(item_prev->tuple);
1614-
}
1600+
hash_seq_init(&rstat,record_src->rhash);
1601+
while ((item_src= (HashRecordEntry*)hash_seq_search(&rstat))!=NULL)
1602+
copy_record(record_dest,item_src->tuple,destVar);
16151603
}
16161604
else
16171605
/* copy scalar value */

‎pg_variables.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ typedef struct ChangesStackNode
151151
externvoidinit_record(RecordVar*record,TupleDesctupdesc,Variable*variable);
152152
externvoidcheck_attributes(Variable*variable,TupleDesctupdesc);
153153
externvoidcheck_record_key(Variable*variable,Oidtypid);
154+
externvoidcopy_record(RecordVar*dest_record,HeapTuplesrc_tuple,
155+
Variable*variable);
154156

155157
externvoidinsert_record(Variable*variable,HeapTupleHeadertupleHeader);
156158
externboolupdate_record(Variable*variable,HeapTupleHeadertupleHeader);

‎pg_variables_record.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,47 @@ init_record(RecordVar *record, TupleDesc tupdesc, Variable *variable)
153153
MemoryContextSwitchTo(oldcxt);
154154
}
155155

156+
/*
157+
* Copy record using src_tuple.
158+
*/
159+
void
160+
copy_record(RecordVar*dest_record,HeapTuplesrc_tuple,Variable*variable)
161+
{
162+
HeapTupletuple;
163+
Datumvalue;
164+
boolisnull;
165+
HashRecordKeyk;
166+
HashRecordEntry*item;
167+
boolfound;
168+
MemoryContextoldcxt;
169+
170+
oldcxt=MemoryContextSwitchTo(dest_record->hctx);
171+
172+
/* Inserting a new record into dest_record */
173+
tuple=heap_copytuple(src_tuple);
174+
value=fastgetattr(tuple,1,dest_record->tupdesc,&isnull);
175+
176+
k.value=value;
177+
k.is_null=isnull;
178+
k.hash_proc=&dest_record->hash_proc;
179+
k.cmp_proc=&dest_record->cmp_proc;
180+
181+
item= (HashRecordEntry*)hash_search(dest_record->rhash,&k,
182+
HASH_ENTER,&found);
183+
if (found)
184+
{
185+
heap_freetuple(tuple);
186+
MemoryContextSwitchTo(oldcxt);
187+
ereport(ERROR,
188+
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
189+
errmsg("there is a record in the variable \"%s\" with same "
190+
"key",GetName(variable))));
191+
}
192+
item->tuple=tuple;
193+
194+
MemoryContextSwitchTo(oldcxt);
195+
}
196+
156197
/*
157198
* New record structure should be the same as the first record.
158199
*/

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp