12
12
*
13
13
*******************************************************************************
14
14
*
15
- * Copyright (c) 2016-2022 , Postgres Professional
15
+ * Copyright (c) 2016-2023 , Postgres Professional
16
16
*
17
17
* IDENTIFICATION
18
18
* aqo/hash.c
@@ -157,6 +157,8 @@ get_grouped_exprs_hash(int child_fss, List *group_exprs)
157
157
final_hashes [0 ] = child_fss ;
158
158
final_hashes [1 ] = get_int_array_hash (hashes , i );
159
159
160
+ pfree (hashes );
161
+
160
162
return get_int_array_hash (final_hashes , 2 );
161
163
}
162
164
@@ -224,6 +226,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
224
226
clause_has_consts [i ] = (args != NULL && has_consts (* args ));
225
227
i ++ ;
226
228
}
229
+ pfree (args_hash );
227
230
228
231
idx = argsort (clause_hashes , n , sizeof (* clause_hashes ), int_cmp );
229
232
inverse_idx = inverse_permutation (idx , n );
@@ -234,6 +237,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
234
237
sorted_clauses [inverse_idx [i ]] = clause_hashes [i ];
235
238
i ++ ;
236
239
}
240
+ pfree (clause_hashes );
237
241
238
242
i = 0 ;
239
243
foreach (lc , selectivities )
@@ -249,6 +253,7 @@ get_fss_for_object(List *relsigns, List *clauselist,
249
253
}
250
254
i ++ ;
251
255
}
256
+ pfree (inverse_idx );
252
257
253
258
for (i = 0 ; i < n ;)
254
259
{
@@ -272,6 +277,8 @@ get_fss_for_object(List *relsigns, List *clauselist,
272
277
sizeof (* * features ), double_cmp );
273
278
i = j ;
274
279
}
280
+ pfree (idx );
281
+ pfree (clause_has_consts );
275
282
276
283
/*
277
284
* Generate feature subspace hash.
@@ -281,6 +288,8 @@ get_fss_for_object(List *relsigns, List *clauselist,
281
288
eclasses_hash = get_int_array_hash (eclass_hash , nargs );
282
289
relations_hash = get_relations_hash (relsigns );
283
290
fss_hash = get_fss_hash (clauses_hash , eclasses_hash , relations_hash );
291
+ pfree (sorted_clauses );
292
+ pfree (eclass_hash );
284
293
285
294
if (nfeatures != NULL )
286
295
{
@@ -340,11 +349,17 @@ static int
340
349
get_node_hash (Node * node )
341
350
{
342
351
char * str ;
352
+ char * no_consts ;
353
+ char * no_locations ;
343
354
int hash ;
344
355
345
- str = remove_locations ( remove_consts ( nodeToString (node )) );
346
- hash = get_str_hash (str );
356
+ str = nodeToString (node );
357
+ no_consts = remove_consts (str );
347
358
pfree (str );
359
+ no_locations = remove_locations (no_consts );
360
+ pfree (no_consts );
361
+ hash = get_str_hash (no_locations );
362
+ pfree (no_locations );
348
363
return hash ;
349
364
}
350
365
@@ -467,6 +482,7 @@ get_relations_hash(List *relsigns)
467
482
468
483
result = DatumGetInt32 (hash_any ((const unsigned char * ) hashes ,
469
484
nhashes * sizeof (uint32 )));
485
+ pfree (hashes );
470
486
471
487
return result ;
472
488
}
@@ -479,9 +495,11 @@ static char *
479
495
remove_consts (const char * str )
480
496
{
481
497
char * res ;
498
+ char * tmp ;
482
499
483
- res = replace_patterns (str , "{CONST" , is_brace );
484
- res = replace_patterns (res , ":stmt_len" , is_brace );
500
+ tmp = replace_patterns (str , "{CONST" , is_brace );
501
+ res = replace_patterns (tmp , ":stmt_len" , is_brace );
502
+ pfree (tmp );
485
503
return res ;
486
504
}
487
505
@@ -683,6 +701,8 @@ get_eclasses(List *clauselist, int *nargs, int **args_hash, int **eclass_hash)
683
701
684
702
for (i = 0 ; i < * nargs ; ++ i )
685
703
(* eclass_hash )[i ] = e_hashes [disjoint_set_get_parent (p , i )];
704
+
705
+ pfree (e_hashes );
686
706
}
687
707
688
708
/*
0 commit comments