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

Commit1c1ffaf

Browse files
committed
improved array reallocation in pathman_rel_pathlist_hook()
1 parentffe595e commit1c1ffaf

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

‎src/hooks.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
196196
RangeTblEntry*rte)
197197
{
198198
constPartRelationInfo*prel;
199-
RangeTblEntry**new_rte_array;
200-
RelOptInfo**new_rel_array;
201-
intlen;
199+
intirange_len;
202200

203201
/* Invoke original hook if needed */
204202
if (set_rel_pathlist_hook_next!=NULL)
@@ -290,35 +288,34 @@ pathman_rel_pathlist_hook(PlannerInfo *root,
290288
}
291289

292290
/* Get number of selected partitions */
293-
len=irange_list_length(ranges);
291+
irange_len=irange_list_length(ranges);
294292
if (prel->enable_parent)
295-
len++;/* add parent too */
293+
irange_len++;/*alsoadd parent */
296294

297295
/* Expand simple_rte_array and simple_rel_array */
298-
if (len>0)
296+
if (irange_len>0)
299297
{
300-
/* Expand simple_rel_array and simple_rte_array */
301-
new_rel_array= (RelOptInfo**)
302-
palloc0((root->simple_rel_array_size+len)*sizeof(RelOptInfo*));
298+
intcurrent_len=root->simple_rel_array_size,
299+
new_len=current_len+irange_len;
303300

304-
/* simple_rte_array is an array equivalent of the rtable list */
305-
new_rte_array= (RangeTblEntry**)
306-
palloc0((root->simple_rel_array_size+len)*sizeof(RangeTblEntry*));
301+
/* Expand simple_rel_array */
302+
root->simple_rel_array= (RelOptInfo**)
303+
repalloc(root->simple_rel_array,
304+
new_len*sizeof(RelOptInfo*));
307305

308-
/* Copy relations to the new arrays */
309-
for (i=0;i<root->simple_rel_array_size;i++)
310-
{
311-
new_rel_array[i]=root->simple_rel_array[i];
312-
new_rte_array[i]=root->simple_rte_array[i];
313-
}
306+
memset((void*)&root->simple_rel_array[current_len],0,
307+
irange_len*sizeof(RelOptInfo*));
308+
309+
/* Expand simple_rte_array */
310+
root->simple_rte_array= (RangeTblEntry**)
311+
repalloc(root->simple_rte_array,
312+
new_len*sizeof(RangeTblEntry*));
314313

315-
/* Free old arrays */
316-
pfree(root->simple_rel_array);
317-
pfree(root->simple_rte_array);
314+
memset((void*)&root->simple_rte_array[current_len],0,
315+
irange_len*sizeof(RangeTblEntry*));
318316

319-
root->simple_rel_array_size+=len;
320-
root->simple_rel_array=new_rel_array;
321-
root->simple_rte_array=new_rte_array;
317+
/* Don't forget to update array size! */
318+
root->simple_rel_array_size=new_len;
322319
}
323320

324321
/* Parent has already been locked by rewriter */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp