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

Commit1d812a9

Browse files
author
Neil Conway
committed
Add a new tuplestore API function, tuplestore_putvalues(). This is
identical to tuplestore_puttuple(), except it operates on arrays ofDatums + nulls rather than a fully-formed HeapTuple. In several placesthat use the tuplestore API, this means we can avoid creating aHeapTuple altogether, saving a copy.
1 parent76cf067 commit1d812a9

File tree

7 files changed

+59
-47
lines changed

7 files changed

+59
-47
lines changed

‎src/backend/commands/prepare.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Copyright (c) 2002-2008, PostgreSQL Global Development Group
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.80 2008/01/01 19:45:49 momjian Exp $
13+
* $PostgreSQL: pgsql/src/backend/commands/prepare.c,v 1.81 2008/03/25 19:26:53 neilc Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -764,7 +764,6 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
764764
hash_seq_init(&hash_seq,prepared_queries);
765765
while ((prep_stmt=hash_seq_search(&hash_seq))!=NULL)
766766
{
767-
HeapTupletuple;
768767
Datumvalues[5];
769768
boolnulls[5];
770769

@@ -787,11 +786,9 @@ pg_prepared_statement(PG_FUNCTION_ARGS)
787786
prep_stmt->plansource->num_params);
788787
values[4]=BoolGetDatum(prep_stmt->from_sql);
789788

790-
tuple=heap_form_tuple(tupdesc,values,nulls);
791-
792789
/* switch to appropriate context while storing the tuple */
793790
MemoryContextSwitchTo(per_query_ctx);
794-
tuplestore_puttuple(tupstore,tuple);
791+
tuplestore_putvalues(tupstore,tupdesc,values,nulls);
795792
}
796793
}
797794

‎src/backend/executor/execQual.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.226 2008/01/01 19:45:49 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/executor/execQual.c,v 1.227 2008/03/25 19:26:53 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1547,7 +1547,6 @@ ExecMakeTableFunctionResult(ExprState *funcexpr,
15471547
for (;;)
15481548
{
15491549
Datumresult;
1550-
HeapTupletuple;
15511550

15521551
CHECK_FOR_INTERRUPTS();
15531552

@@ -1649,15 +1648,15 @@ ExecMakeTableFunctionResult(ExprState *funcexpr,
16491648
*/
16501649
tmptup.t_len=HeapTupleHeaderGetDatumLength(td);
16511650
tmptup.t_data=td;
1652-
tuple=&tmptup;
1651+
1652+
oldcontext=MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
1653+
tuplestore_puttuple(tupstore,&tmptup);
16531654
}
16541655
else
16551656
{
1656-
tuple=heap_form_tuple(tupdesc,&result,&fcinfo.isnull);
1657+
oldcontext=MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
1658+
tuplestore_putvalues(tupstore,tupdesc,&result,&fcinfo.isnull);
16571659
}
1658-
1659-
oldcontext=MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
1660-
tuplestore_puttuple(tupstore,tuple);
16611660
MemoryContextSwitchTo(oldcontext);
16621661

16631662
/*
@@ -1702,15 +1701,13 @@ ExecMakeTableFunctionResult(ExprState *funcexpr,
17021701
intnatts=expectedDesc->natts;
17031702
Datum*nulldatums;
17041703
bool*nullflags;
1705-
HeapTupletuple;
17061704

17071705
MemoryContextSwitchTo(econtext->ecxt_per_tuple_memory);
17081706
nulldatums= (Datum*)palloc0(natts*sizeof(Datum));
17091707
nullflags= (bool*)palloc(natts*sizeof(bool));
17101708
memset(nullflags, true,natts*sizeof(bool));
1711-
tuple=heap_form_tuple(expectedDesc,nulldatums,nullflags);
17121709
MemoryContextSwitchTo(econtext->ecxt_per_query_memory);
1713-
tuplestore_puttuple(tupstore,tuple);
1710+
tuplestore_putvalues(tupstore,expectedDesc,nulldatums,nullflags);
17141711
}
17151712
}
17161713

‎src/backend/utils/mmgr/portalmem.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Portions Copyright (c) 1994, Regents of the University of California
1313
*
1414
* IDENTIFICATION
15-
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.106 2008/01/01 19:45:55 momjian Exp $
15+
* $PostgreSQL: pgsql/src/backend/utils/mmgr/portalmem.c,v 1.107 2008/03/25 19:26:53 neilc Exp $
1616
*
1717
*-------------------------------------------------------------------------
1818
*/
@@ -911,7 +911,6 @@ pg_cursor(PG_FUNCTION_ARGS)
911911
while ((hentry=hash_seq_search(&hash_seq))!=NULL)
912912
{
913913
Portalportal=hentry->portal;
914-
HeapTupletuple;
915914
Datumvalues[6];
916915
boolnulls[6];
917916

@@ -935,11 +934,9 @@ pg_cursor(PG_FUNCTION_ARGS)
935934
values[4]=BoolGetDatum(portal->cursorOptions&CURSOR_OPT_SCROLL);
936935
values[5]=TimestampTzGetDatum(portal->creation_time);
937936

938-
tuple=heap_form_tuple(tupdesc,values,nulls);
939-
940937
/* switch to appropriate context while storing the tuple */
941938
MemoryContextSwitchTo(per_query_ctx);
942-
tuplestore_puttuple(tupstore,tuple);
939+
tuplestore_putvalues(tupstore,tupdesc,values,nulls);
943940
}
944941

945942
/* clean up and return the tuplestore */

‎src/backend/utils/sort/tuplestore.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
* Portions Copyright (c) 1994, Regents of the University of California
3939
*
4040
* IDENTIFICATION
41-
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.37 2008/03/10 20:06:27 tgl Exp $
41+
* $PostgreSQL: pgsql/src/backend/utils/sort/tuplestore.c,v 1.38 2008/03/25 19:26:53 neilc Exp $
4242
*
4343
*-------------------------------------------------------------------------
4444
*/
@@ -366,8 +366,6 @@ tuplestore_puttupleslot(Tuplestorestate *state,
366366
/*
367367
* "Standard" case to copy from a HeapTuple. This is actually now somewhat
368368
* deprecated, but not worth getting rid of in view of the number of callers.
369-
* (Consider adding something that takes a tupdesc+values/nulls arrays so
370-
* that we can use heap_form_minimal_tuple() and avoid a copy step.)
371369
*/
372370
void
373371
tuplestore_puttuple(Tuplestorestate*state,HeapTupletuple)
@@ -380,6 +378,22 @@ tuplestore_puttuple(Tuplestorestate *state, HeapTuple tuple)
380378
tuplestore_puttuple_common(state, (void*)tuple);
381379
}
382380

381+
/*
382+
* Similar to tuplestore_puttuple(), but start from the values + nulls
383+
* array. This avoids requiring that the caller construct a HeapTuple,
384+
* saving a copy.
385+
*/
386+
void
387+
tuplestore_putvalues(Tuplestorestate*state,TupleDesctdesc,
388+
Datum*values,bool*isnull)
389+
{
390+
MinimalTupletuple;
391+
392+
tuple=heap_form_minimal_tuple(tdesc,values,isnull);
393+
394+
tuplestore_puttuple_common(state, (void*)tuple);
395+
}
396+
383397
staticvoid
384398
tuplestore_puttuple_common(Tuplestorestate*state,void*tuple)
385399
{

‎src/include/utils/tuplestore.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
2323
* Portions Copyright (c) 1994, Regents of the University of California
2424
*
25-
* $PostgreSQL: pgsql/src/include/utils/tuplestore.h,v 1.22 2008/01/01 19:45:59 momjian Exp $
25+
* $PostgreSQL: pgsql/src/include/utils/tuplestore.h,v 1.23 2008/03/25 19:26:53 neilc Exp $
2626
*
2727
*-------------------------------------------------------------------------
2828
*/
@@ -51,6 +51,8 @@ extern void tuplestore_set_eflags(Tuplestorestate *state, int eflags);
5151
externvoidtuplestore_puttupleslot(Tuplestorestate*state,
5252
TupleTableSlot*slot);
5353
externvoidtuplestore_puttuple(Tuplestorestate*state,HeapTupletuple);
54+
externvoidtuplestore_putvalues(Tuplestorestate*state,TupleDesctdesc,
55+
Datum*values,bool*isnull);
5456

5557
/* tuplestore_donestoring() used to be required, but is no longer used */
5658
#definetuplestore_donestoring(state)((void) 0)

‎src/pl/plperl/plperl.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plperl.c - perl as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.136 2008/01/23 00:55:47 adunstan Exp $
4+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.137 2008/03/25 19:26:53 neilc Exp $
55
*
66
**********************************************************************/
77

@@ -1869,7 +1869,6 @@ plperl_return_next(SV *sv)
18691869
FunctionCallInfofcinfo;
18701870
ReturnSetInfo*rsi;
18711871
MemoryContextold_cxt;
1872-
HeapTupletuple;
18731872

18741873
if (!sv)
18751874
return;
@@ -1944,8 +1943,15 @@ plperl_return_next(SV *sv)
19441943

19451944
if (prodesc->fn_retistuple)
19461945
{
1946+
HeapTupletuple;
1947+
19471948
tuple=plperl_build_tuple_result((HV*)SvRV(sv),
19481949
current_call_data->attinmeta);
1950+
1951+
/* Make sure to store the tuple in a long-lived memory context */
1952+
MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
1953+
tuplestore_puttuple(current_call_data->tuple_store,tuple);
1954+
MemoryContextSwitchTo(old_cxt);
19491955
}
19501956
else
19511957
{
@@ -1967,14 +1973,14 @@ plperl_return_next(SV *sv)
19671973
isNull= true;
19681974
}
19691975

1970-
tuple=heap_form_tuple(current_call_data->ret_tdesc,&ret,&isNull);
1976+
/* Make sure to store the tuple in a long-lived memory context */
1977+
MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
1978+
tuplestore_putvalues(current_call_data->tuple_store,
1979+
current_call_data->ret_tdesc,
1980+
&ret,&isNull);
1981+
MemoryContextSwitchTo(old_cxt);
19711982
}
19721983

1973-
/* Make sure to store the tuple in a long-lived memory context */
1974-
MemoryContextSwitchTo(rsi->econtext->ecxt_per_query_memory);
1975-
tuplestore_puttuple(current_call_data->tuple_store,tuple);
1976-
MemoryContextSwitchTo(old_cxt);
1977-
19781984
MemoryContextReset(current_call_data->tmp_cxt);
19791985
}
19801986

‎src/pl/plpgsql/src/pl_exec.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.202 2008/01/01 19:46:00 momjian Exp $
11+
* $PostgreSQL: pgsql/src/pl/plpgsql/src/pl_exec.c,v 1.203 2008/03/25 19:26:54 neilc Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2007,10 +2007,11 @@ static int
20072007
exec_stmt_return_next(PLpgSQL_execstate*estate,
20082008
PLpgSQL_stmt_return_next*stmt)
20092009
{
2010-
TupleDesctupdesc;
2011-
intnatts;
2012-
HeapTupletuple;
2013-
boolfree_tuple= false;
2010+
TupleDesctupdesc;
2011+
intnatts;
2012+
MemoryContextoldcxt;
2013+
HeapTupletuple=NULL;
2014+
boolfree_tuple= false;
20142015

20152016
if (!estate->retisset)
20162017
ereport(ERROR,
@@ -2048,9 +2049,10 @@ exec_stmt_return_next(PLpgSQL_execstate *estate,
20482049
tupdesc->attrs[0]->atttypmod,
20492050
isNull);
20502051

2051-
tuple=heap_form_tuple(tupdesc,&retval,&isNull);
2052-
2053-
free_tuple= true;
2052+
oldcxt=MemoryContextSwitchTo(estate->tuple_store_cxt);
2053+
tuplestore_putvalues(estate->tuple_store,tupdesc,
2054+
&retval,&isNull);
2055+
MemoryContextSwitchTo(oldcxt);
20542056
}
20552057
break;
20562058

@@ -2087,7 +2089,6 @@ exec_stmt_return_next(PLpgSQL_execstate *estate,
20872089

20882090
default:
20892091
elog(ERROR,"unrecognized dtype: %d",retvar->dtype);
2090-
tuple=NULL;/* keep compiler quiet */
20912092
break;
20922093
}
20932094
}
@@ -2114,9 +2115,10 @@ exec_stmt_return_next(PLpgSQL_execstate *estate,
21142115
tupdesc->attrs[0]->atttypmod,
21152116
isNull);
21162117

2117-
tuple=heap_form_tuple(tupdesc,&retval,&isNull);
2118-
2119-
free_tuple= true;
2118+
oldcxt=MemoryContextSwitchTo(estate->tuple_store_cxt);
2119+
tuplestore_putvalues(estate->tuple_store,tupdesc,
2120+
&retval,&isNull);
2121+
MemoryContextSwitchTo(oldcxt);
21202122

21212123
exec_eval_cleanup(estate);
21222124
}
@@ -2125,13 +2127,10 @@ exec_stmt_return_next(PLpgSQL_execstate *estate,
21252127
ereport(ERROR,
21262128
(errcode(ERRCODE_SYNTAX_ERROR),
21272129
errmsg("RETURN NEXT must have a parameter")));
2128-
tuple=NULL;/* keep compiler quiet */
21292130
}
21302131

21312132
if (HeapTupleIsValid(tuple))
21322133
{
2133-
MemoryContextoldcxt;
2134-
21352134
oldcxt=MemoryContextSwitchTo(estate->tuple_store_cxt);
21362135
tuplestore_puttuple(estate->tuple_store,tuple);
21372136
MemoryContextSwitchTo(oldcxt);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp