@@ -334,16 +334,16 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type,
334
334
335
335
PG_TRY ();
336
336
{
337
- const PartRelationInfo * prel ;
338
- LockAcquireResult lock_result ; /* could we lock the parent? */
339
- Datum values [Natts_pathman_config ];
340
- bool isnull [Natts_pathman_config ];
337
+ LockAcquireResult lock_result ; /* could we lock the parent? */
338
+ Datum values [Natts_pathman_config ];
339
+ bool isnull [Natts_pathman_config ];
341
340
342
341
/* Get both PartRelationInfo & PATHMAN_CONFIG contents for this relation */
343
342
if (pathman_config_contains_relation (relid , values , isnull , NULL , NULL ))
344
343
{
345
- Oid base_bound_type ; /* base type of prel->ev_type */
346
- Oid base_value_type ; /* base type of value_type */
344
+ PartRelationInfo * prel ;
345
+ Oid base_bound_type ; /* base type of prel->ev_type */
346
+ Oid base_value_type ; /* base type of value_type */
347
347
348
348
/* Fetch PartRelationInfo by 'relid' */
349
349
prel = get_pathman_relation_info_after_lock (relid , true, & lock_result );
@@ -426,6 +426,9 @@ create_partitions_for_value_internal(Oid relid, Datum value, Oid value_type,
426
426
value , base_value_type ,
427
427
prel -> ev_collid );
428
428
}
429
+
430
+ /* Don't forget to close 'prel'! */
431
+ close_pathman_relation_info (prel );
429
432
}
430
433
else
431
434
elog (ERROR , "table \"%s\" is not partitioned" ,
@@ -1356,56 +1359,57 @@ check_range_available(Oid parent_relid,
1356
1359
Oid value_type ,
1357
1360
bool raise_error )
1358
1361
{
1359
- const PartRelationInfo * prel ;
1360
- RangeEntry * ranges ;
1361
- FmgrInfo cmp_func ;
1362
- uint32 i ;
1362
+ PartRelationInfo * prel ;
1363
+ bool result = true;
1363
1364
1364
1365
/* Try fetching the PartRelationInfo structure */
1365
- prel = get_pathman_relation_info (parent_relid );
1366
-
1367
- /* If there's no prel, return TRUE (overlap is not possible) */
1368
- if (!prel )
1366
+ if ((prel = get_pathman_relation_info (parent_relid )) != NULL )
1369
1367
{
1370
- ereport (WARNING , (errmsg ("table \"%s\" is not partitioned" ,
1371
- get_rel_name_or_relid (parent_relid ))));
1372
- return true;
1373
- }
1368
+ RangeEntry * ranges ;
1369
+ FmgrInfo cmp_func ;
1370
+ uint32 i ;
1374
1371
1375
- /* Emit an error if it is not partitioned by RANGE */
1376
- shout_if_prel_is_invalid (parent_relid , prel , PT_RANGE );
1372
+ /* Emit an error if it is not partitioned by RANGE */
1373
+ shout_if_prel_is_invalid (parent_relid , prel , PT_RANGE );
1377
1374
1378
- /* Fetch comparison function */
1379
- fill_type_cmp_fmgr_info (& cmp_func ,
1380
- getBaseType (value_type ),
1381
- getBaseType (prel -> ev_type ));
1375
+ /* Fetch comparison function */
1376
+ fill_type_cmp_fmgr_info (& cmp_func ,
1377
+ getBaseType (value_type ),
1378
+ getBaseType (prel -> ev_type ));
1382
1379
1383
- ranges = PrelGetRangesArray (prel );
1384
- for (i = 0 ; i < PrelChildrenCount (prel ); i ++ )
1385
- {
1386
- int c1 , c2 ;
1380
+ ranges = PrelGetRangesArray (prel );
1381
+ for (i = 0 ; i < PrelChildrenCount (prel ); i ++ )
1382
+ {
1383
+ int c1 , c2 ;
1387
1384
1388
- c1 = cmp_bounds (& cmp_func , prel -> ev_collid , start , & ranges [i ].max );
1389
- c2 = cmp_bounds (& cmp_func , prel -> ev_collid , end , & ranges [i ].min );
1385
+ c1 = cmp_bounds (& cmp_func , prel -> ev_collid , start , & ranges [i ].max );
1386
+ c2 = cmp_bounds (& cmp_func , prel -> ev_collid , end , & ranges [i ].min );
1390
1387
1391
- /* There's something! */
1392
- if (c1 < 0 && c2 > 0 )
1393
- {
1394
- if (raise_error )
1395
- elog (ERROR , "specified range [%s, %s) overlaps "
1396
- "with existing partitions" ,
1397
- IsInfinite (start ) ?
1398
- "NULL" :
1399
- datum_to_cstring (BoundGetValue (start ), value_type ),
1400
- IsInfinite (end ) ?
1401
- "NULL" :
1402
- datum_to_cstring (BoundGetValue (end ), value_type ));
1403
-
1404
- else return false;
1388
+ /* There's something! */
1389
+ if (c1 < 0 && c2 > 0 )
1390
+ {
1391
+ if (raise_error )
1392
+ {
1393
+ elog (ERROR , "specified range [%s, %s) overlaps "
1394
+ "with existing partitions" ,
1395
+ BoundToCString (start , value_type ),
1396
+ BoundToCString (end , value_type ));
1397
+ }
1398
+ /* Too bad, so sad */
1399
+ else result = false;
1400
+ }
1405
1401
}
1402
+
1403
+ /* Don't forget to close 'prel'! */
1404
+ close_pathman_relation_info (prel );
1405
+ }
1406
+ else
1407
+ {
1408
+ ereport (WARNING , (errmsg ("table \"%s\" is not partitioned" ,
1409
+ get_rel_name_or_relid (parent_relid ))));
1406
1410
}
1407
1411
1408
- return true ;
1412
+ return result ;
1409
1413
}
1410
1414
1411
1415
/* Build HASH check constraint expression tree */
@@ -1669,15 +1673,15 @@ invoke_init_callback_internal(init_callback_params *cb_params)
1669
1673
* end_value = NULL ;
1670
1674
Bound sv_datum = cb_params -> params .range_params .start_value ,
1671
1675
ev_datum = cb_params -> params .range_params .end_value ;
1672
- Oid type = cb_params -> params .range_params .value_type ;
1676
+ Oid value_type = cb_params -> params .range_params .value_type ;
1673
1677
1674
1678
/* Convert min to CSTRING */
1675
1679
if (!IsInfinite (& sv_datum ))
1676
- start_value = datum_to_cstring ( BoundGetValue ( & sv_datum ), type );
1680
+ start_value = BoundToCString ( & sv_datum , value_type );
1677
1681
1678
1682
/* Convert max to CSTRING */
1679
1683
if (!IsInfinite (& ev_datum ))
1680
- end_value = datum_to_cstring ( BoundGetValue ( & ev_datum ), type );
1684
+ end_value = BoundToCString ( & ev_datum , value_type );
1681
1685
1682
1686
pushJsonbValue (& jsonb_state , WJB_BEGIN_OBJECT , NULL );
1683
1687
@@ -1861,42 +1865,3 @@ build_partitioning_expression(Oid parent_relid,
1861
1865
1862
1866
return expr ;
1863
1867
}
1864
-
1865
- /*
1866
- * -------------------------
1867
- * Update triggers management
1868
- * -------------------------
1869
- */
1870
-
1871
- /* Create trigger for partition */
1872
- void
1873
- create_single_update_trigger_internal (Oid partition_relid ,
1874
- const char * trigname ,
1875
- List * columns )
1876
- {
1877
- CreateTrigStmt * stmt ;
1878
- List * func ;
1879
-
1880
- func = list_make2 (makeString (get_namespace_name (get_pathman_schema ())),
1881
- makeString (CppAsString (pathman_update_trigger_func )));
1882
-
1883
- stmt = makeNode (CreateTrigStmt );
1884
- stmt -> trigname = (char * ) trigname ;
1885
- stmt -> relation = makeRangeVarFromRelid (partition_relid );
1886
- stmt -> funcname = func ;
1887
- stmt -> args = NIL ;
1888
- stmt -> row = true;
1889
- stmt -> timing = TRIGGER_TYPE_BEFORE ;
1890
- stmt -> events = TRIGGER_TYPE_UPDATE ;
1891
- stmt -> columns = columns ;
1892
- stmt -> whenClause = NULL ;
1893
- stmt -> isconstraint = false;
1894
- stmt -> deferrable = false;
1895
- stmt -> initdeferred = false;
1896
- stmt -> constrrel = NULL ;
1897
-
1898
- (void ) CreateTrigger (stmt , NULL , InvalidOid , InvalidOid ,
1899
- InvalidOid , InvalidOid , false);
1900
-
1901
- CommandCounterIncrement ();
1902
- }
0 commit comments