@@ -278,12 +278,10 @@ ts_chunk_constraint_dimensional_create(const Dimension *dim, const DimensionSlic
278278 const char * name )
279279{
280280 Constraint * constr = NULL ;
281- bool isvarlena ;
282281 Node * dimdef ;
283282 ColumnRef * colref ;
284- Datum startdat , enddat ;
285283 List * compexprs = NIL ;
286- Oid outfuncid ;
284+ Oid type ;
287285
288286 if (slice -> fd .range_start == PG_INT64_MIN && slice -> fd .range_end == PG_INT64_MAX )
289287 return NULL ;
@@ -308,16 +306,12 @@ ts_chunk_constraint_dimensional_create(const Dimension *dim, const DimensionSlic
308306 /* The dimension has a time function to compute the time value so
309307 * need to convert the range values to the time type returned by
310308 * the partitioning function. */
311- getTypeOutputInfo (partinfo -> partfunc .rettype , & outfuncid , & isvarlena );
312- startdat = ts_internal_to_time_value (slice -> fd .range_start , partinfo -> partfunc .rettype );
313- enddat = ts_internal_to_time_value (slice -> fd .range_end , partinfo -> partfunc .rettype );
309+ type = partinfo -> partfunc .rettype ;
314310 }
315311 else
316312 {
317- /* Closed dimension, just use the integer output function */
318- getTypeOutputInfo (INT8OID , & outfuncid , & isvarlena );
319- startdat = Int64GetDatum (slice -> fd .range_start );
320- enddat = Int64GetDatum (slice -> fd .range_end );
313+ /* Closed dimension, just use the INT8 type */
314+ type = INT8OID ;
321315 }
322316 }
323317 else
@@ -326,28 +320,24 @@ ts_chunk_constraint_dimensional_create(const Dimension *dim, const DimensionSlic
326320 Assert (IS_OPEN_DIMENSION (dim ));
327321
328322 dimdef = (Node * ) colref ;
329- getTypeOutputInfo (dim -> fd .column_type , & outfuncid , & isvarlena );
330- startdat = ts_internal_to_time_value (slice -> fd .range_start , dim -> fd .column_type );
331- enddat = ts_internal_to_time_value (slice -> fd .range_end , dim -> fd .column_type );
323+ type = dim -> fd .column_type ;
332324 }
333325
334326 /*
335- * Convert internal format datums to string (output) datums.
336- *
337327 * We are forcing ISO datestyle here to prevent parsing errors with
338328 * certain timezone/datestyle combinations.
339329 */
340330 int current_datestyle = DateStyle ;
341331 DateStyle = USE_ISO_DATES ;
342- startdat = OidFunctionCall1 ( outfuncid , startdat );
343- enddat = OidFunctionCall1 ( outfuncid , enddat );
332+ char * start_str = ts_internal_to_time_string ( slice -> fd . range_start , type );
333+ char * end_str = ts_internal_to_time_string ( slice -> fd . range_end , type );
344334 DateStyle = current_datestyle ;
345335
346336 /* Elide range constraint for +INF or -INF */
347337 if (slice -> fd .range_start != PG_INT64_MIN )
348338 {
349339 A_Const * start_const = makeNode (A_Const );
350- memcpy (& start_const -> val , makeString (DatumGetCString ( startdat ) ), sizeof (start_const -> val ));
340+ memcpy (& start_const -> val , makeString (start_str ), sizeof (start_const -> val ));
351341 start_const -> location = -1 ;
352342 A_Expr * ge_expr = makeSimpleA_Expr (AEXPR_OP , ">=" , dimdef , (Node * ) start_const , -1 );
353343 compexprs = lappend (compexprs , ge_expr );
@@ -356,7 +346,7 @@ ts_chunk_constraint_dimensional_create(const Dimension *dim, const DimensionSlic
356346 if (slice -> fd .range_end != PG_INT64_MAX )
357347 {
358348 A_Const * end_const = makeNode (A_Const );
359- memcpy (& end_const -> val , makeString (DatumGetCString ( enddat ) ), sizeof (end_const -> val ));
349+ memcpy (& end_const -> val , makeString (end_str ), sizeof (end_const -> val ));
360350 end_const -> location = -1 ;
361351 A_Expr * lt_expr = makeSimpleA_Expr (AEXPR_OP , "<" , dimdef , (Node * ) end_const , -1 );
362352 compexprs = lappend (compexprs , lt_expr );
0 commit comments