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

Commit35e6d57

Browse files
author
Nikita Glukhov
committed
Fix jsonb iterator freeing
1 parent64c19e4 commit35e6d57

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

‎src/backend/access/common/detoast.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ create_detoast_iterator(struct varlena *attr)
4242
iter= (DetoastIterator)palloc0(sizeof(DetoastIteratorData));
4343
iter->done= false;
4444
iter->nrefs=1;
45-
iter->gen.free= (void (*)(void*))free_detoast_iterator;
45+
iter->gen.free_callback.func= (void (*)(void*))free_detoast_iterator;
4646

4747
/* This is an externally stored datum --- initialize fetch datum iterator */
4848
iter->fetch_datum_iterator=fetch_iter=create_fetch_datum_iterator(attr);
@@ -87,7 +87,7 @@ create_detoast_iterator(struct varlena *attr)
8787
iter= (DetoastIterator)palloc0(sizeof(DetoastIteratorData));
8888
iter->done= false;
8989
iter->nrefs=1;
90-
iter->gen.free= (void (*)(void*))free_detoast_iterator;
90+
iter->gen.free_callback.func= (void (*)(void*))free_detoast_iterator;
9191

9292
iter->fetch_datum_iterator=palloc0(sizeof(*iter->fetch_datum_iterator));
9393
iter->fetch_datum_iterator->buf=buf=create_toast_buffer(VARSIZE_ANY(attr), true);

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

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,7 +2961,6 @@ jsonbzIteratorInit(JsonContainer *jc)
29612961
returnjsonbIteratorInitExt(jc,jbc,cjb);
29622962
}
29632963

2964-
#defineJSONB_FREE_ITERATORS
29652964
#ifdefJSONB_FREE_ITERATORS
29662965
staticstruct
29672966
{
@@ -3003,20 +3002,20 @@ jsonbzInitFromDetoastIterator(JsonContainerData *jc, DetoastIterator iter)
30033002
#endif
30043003
}
30053004

3005+
#ifdefJSONB_FREE_ITERATORS
30063006
void
30073007
jsonbInitIterators(void)
30083008
{
3009-
#ifdefJSONB_FREE_ITERATORS
30103009
jsonb_detoast_iterators=palloc(sizeof(*jsonb_detoast_iterators));
30113010
jsonb_detoast_iterators->mcxt=CurrentMemoryContext;
30123011
jsonb_detoast_iterators->iterators=NIL;
3013-
#endif
30143012
}
3013+
#endif
30153014

3015+
#ifdefJSONB_FREE_ITERATORS
30163016
void
30173017
jsonbFreeIterators(void)
30183018
{
3019-
#ifdefJSONB_FREE_ITERATORS
30203019
ListCell*lc;
30213020

30223021
if (jsonb_detoast_iterators)
@@ -3031,20 +3030,28 @@ jsonbFreeIterators(void)
30313030
pfree(jsonb_detoast_iterators);
30323031
jsonb_detoast_iterators=NULL;
30333032
}
3034-
#endif
30353033
}
3034+
#endif
30363035

3036+
#ifdefJSONB_FREE_ITERATORS
30373037
MemoryContext
30383038
jsonbGetIteratorContext(void)
30393039
{
30403040
returnjsonb_detoast_iterators ?jsonb_detoast_iterators->mcxt :NULL;
30413041
}
3042+
#endif
30423043

30433044
void
30443045
jsonbRegisterIterator(GenericDetoastIteratoriter)
30453046
{
3047+
#ifndefJSONB_FREE_ITERATORS
3048+
//iter->free_callback.func = iter->free;
3049+
iter->free_callback.arg=iter;
3050+
MemoryContextRegisterResetCallback(CurrentMemoryContext,&iter->free_callback);
3051+
#else
30463052
if (jsonb_detoast_iterators)
30473053
jsonb_detoast_iterators->iterators=lappend(jsonb_detoast_iterators->iterators,iter);
3054+
#endif
30483055
}
30493056

30503057
staticvoid
@@ -3079,6 +3086,8 @@ jsonbzInit(JsonContainerData *jc, Datum value)
30793086
jsonbRegisterIterator(&iter->gen);
30803087
MemoryContextSwitchTo(oldcxt);
30813088
}
3089+
#else
3090+
jsonbRegisterIterator(&iter->gen);
30823091
#endif
30833092

30843093
jsonbzInitFromDetoastIterator(jc,iter);
@@ -3172,6 +3181,8 @@ DatumGetJsonbPC(Datum datum, Json *tmp, bool copy)
31723181
jsonbRegisterIterator(&iter->gen);
31733182
MemoryContextSwitchTo(oldcxt);
31743183
}
3184+
# else
3185+
jsonbRegisterIterator(&iter->gen);
31753186
# endif
31763187
#endif
31773188

‎src/include/access/detoast.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ typedef struct FetchDatumIteratorData *FetchDatumIterator;
9595

9696
typedefstructGenericDetoastIteratorData
9797
{
98-
void (*free)(void*iter);
98+
MemoryContextCallbackfree_callback;
9999
}GenericDetoastIteratorData,*GenericDetoastIterator;
100100

101101
typedefstructDetoastIteratorData

‎src/include/utils/jsonb.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,15 @@ extern bool jsonb_sort_field_values;/* GUC */
255255
externbooljsonb_partial_decompression;/* GUC */
256256
externbooljsonb_partial_detoast;/* GUC */
257257

258+
//#define JSONB_FREE_ITERATORS
259+
#ifdefJSONB_FREE_ITERATORS
258260
externvoidjsonbInitIterators(void);
259261
externvoidjsonbFreeIterators(void);
260262
externMemoryContextjsonbGetIteratorContext(void);
263+
#else
264+
# definejsonbInitIterators() ((void) 0)
265+
# definejsonbFreeIterators() ((void) 0)
266+
#endif
261267
externvoidjsonbRegisterIterator(GenericDetoastIteratoriter);
262268

263269
#endif/* __JSONB_H__ */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp