mirror of
https://github.com/postgres/postgres.git
synced 2025-06-14 18:42:34 +03:00
Tweak accumArrayResult() to double the size of its working arrays when
more space is needed, instead of incrementing by a fixed amount; the old method wastes lots of space and time when the ultimate size is large. Per gripe from Tatsuo.
This commit is contained in:
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.134 2006/10/06 17:13:59 petere Exp $
|
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayfuncs.c,v 1.135 2006/11/08 19:24:38 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -4337,10 +4337,9 @@ accumArrayResult(ArrayBuildState *astate,
|
|||||||
oldcontext = MemoryContextSwitchTo(arr_context);
|
oldcontext = MemoryContextSwitchTo(arr_context);
|
||||||
astate = (ArrayBuildState *) palloc(sizeof(ArrayBuildState));
|
astate = (ArrayBuildState *) palloc(sizeof(ArrayBuildState));
|
||||||
astate->mcontext = arr_context;
|
astate->mcontext = arr_context;
|
||||||
astate->dvalues = (Datum *)
|
astate->alen = 64; /* arbitrary starting array size */
|
||||||
palloc(ARRAY_ELEMS_CHUNKSIZE * sizeof(Datum));
|
astate->dvalues = (Datum *) palloc(astate->alen * sizeof(Datum));
|
||||||
astate->dnulls = (bool *)
|
astate->dnulls = (bool *) palloc(astate->alen * sizeof(bool));
|
||||||
palloc(ARRAY_ELEMS_CHUNKSIZE * sizeof(bool));
|
|
||||||
astate->nelems = 0;
|
astate->nelems = 0;
|
||||||
astate->element_type = element_type;
|
astate->element_type = element_type;
|
||||||
get_typlenbyvalalign(element_type,
|
get_typlenbyvalalign(element_type,
|
||||||
@ -4353,14 +4352,13 @@ accumArrayResult(ArrayBuildState *astate,
|
|||||||
oldcontext = MemoryContextSwitchTo(astate->mcontext);
|
oldcontext = MemoryContextSwitchTo(astate->mcontext);
|
||||||
Assert(astate->element_type == element_type);
|
Assert(astate->element_type == element_type);
|
||||||
/* enlarge dvalues[]/dnulls[] if needed */
|
/* enlarge dvalues[]/dnulls[] if needed */
|
||||||
if ((astate->nelems % ARRAY_ELEMS_CHUNKSIZE) == 0)
|
if (astate->nelems >= astate->alen)
|
||||||
{
|
{
|
||||||
|
astate->alen *= 2;
|
||||||
astate->dvalues = (Datum *)
|
astate->dvalues = (Datum *)
|
||||||
repalloc(astate->dvalues,
|
repalloc(astate->dvalues, astate->alen * sizeof(Datum));
|
||||||
(astate->nelems + ARRAY_ELEMS_CHUNKSIZE) * sizeof(Datum));
|
|
||||||
astate->dnulls = (bool *)
|
astate->dnulls = (bool *)
|
||||||
repalloc(astate->dnulls,
|
repalloc(astate->dnulls, astate->alen * sizeof(bool));
|
||||||
(astate->nelems + ARRAY_ELEMS_CHUNKSIZE) * sizeof(bool));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
* Portions Copyright (c) 1996-2006, PostgreSQL Global Development Group
|
||||||
* Portions Copyright (c) 1994, Regents of the University of California
|
* Portions Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $PostgreSQL: pgsql/src/include/utils/array.h,v 1.59 2006/09/10 20:14:20 tgl Exp $
|
* $PostgreSQL: pgsql/src/include/utils/array.h,v 1.60 2006/11/08 19:24:38 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -78,13 +78,8 @@ typedef struct ArrayBuildState
|
|||||||
MemoryContext mcontext; /* where all the temp stuff is kept */
|
MemoryContext mcontext; /* where all the temp stuff is kept */
|
||||||
Datum *dvalues; /* array of accumulated Datums */
|
Datum *dvalues; /* array of accumulated Datums */
|
||||||
bool *dnulls; /* array of is-null flags for Datums */
|
bool *dnulls; /* array of is-null flags for Datums */
|
||||||
|
int alen; /* allocated length of above arrays */
|
||||||
/*
|
int nelems; /* number of valid entries in above arrays */
|
||||||
* The allocated size of dvalues[] and dnulls[] is always a multiple of
|
|
||||||
* ARRAY_ELEMS_CHUNKSIZE
|
|
||||||
*/
|
|
||||||
#define ARRAY_ELEMS_CHUNKSIZE 64
|
|
||||||
int nelems; /* number of valid Datums in dvalues[] */
|
|
||||||
Oid element_type; /* data type of the Datums */
|
Oid element_type; /* data type of the Datums */
|
||||||
int16 typlen; /* needed info about datatype */
|
int16 typlen; /* needed info about datatype */
|
||||||
bool typbyval;
|
bool typbyval;
|
||||||
|
Reference in New Issue
Block a user