绕过printtup的dataoutput的functioncall

This commit is contained in:
y30036740 2023-02-03 11:34:31 +08:00 committed by yyl
parent 8deef3fa1e
commit a452732a6d
5 changed files with 30 additions and 0 deletions

View File

@ -212,6 +212,28 @@ Datum date_out(PG_FUNCTION_ARGS)
PG_RETURN_CSTRING(result);
}
char* output_date_out(DateADT date)
{
char* result = NULL;
struct pg_tm tt, *tm = &tt;
u_sess->utils_cxt.dateoutput_buffer[0] = '\0';
if (DATE_NOT_FINITE(date))
EncodeSpecialDate(date, u_sess->utils_cxt.dateoutput_buffer, MAXDATELEN + 1);
else {
if (unlikely(date > 0 && (INT_MAX - date < POSTGRES_EPOCH_JDATE))) {
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("input julian date is overflow")));
}
j2date(date + POSTGRES_EPOCH_JDATE, &(tm->tm_year), &(tm->tm_mon), &(tm->tm_mday));
EncodeDateOnly(tm, u_sess->time_cxt.DateStyle, u_sess->utils_cxt.dateoutput_buffer);
}
return u_sess->utils_cxt.dateoutput_buffer;
}
/*
* date_recv - converts external binary format to date
*/

View File

@ -471,6 +471,7 @@ static void knl_u_utils_init(knl_u_utils_context* utils_cxt)
utils_cxt->int16output_buffer = (char*)palloc0(128);
utils_cxt->varcharoutput_buffer = (char*)palloc0(256);
utils_cxt->numericoutput_buffer = (char*)palloc0(64);
utils_cxt->dateoutput_buffer = (char*)palloc0(MAXDATELEN + 1);
(void)syscalllockInit(&utils_cxt->deleMemContextMutex);
}

View File

@ -36,6 +36,7 @@
#include "executor/exec/execStream.h"
#include "access/heapam.h"
#include "utils/memutils.h"
#include "catalog/pg_proc.h"
static void printtup_startup(DestReceiver *self, int operation, TupleDesc typeinfo);
static void printtup_20(TupleTableSlot *slot, DestReceiver *self);
@ -1119,6 +1120,9 @@ void printtup(TupleTableSlot *slot, DestReceiver *self)
case F_NUMERIC_OUT:
outputstr = output_numeric_out(DatumGetNumeric(attr));
break;
case F_DATE_OUT:
outputstr = output_date_out(DatumGetDateADT(attr));
break;
default:
outputstr = OutputFunctionCall(&thisState->finfo, attr);
break;

View File

@ -650,6 +650,7 @@ typedef struct knl_u_utils_context {
char* int16output_buffer;
char* varcharoutput_buffer;
char* numericoutput_buffer;
char* dateoutput_buffer;
syscalllock deleMemContextMutex;
} knl_u_utils_context;

View File

@ -24,6 +24,7 @@
#include "lib/stringinfo.h"
#endif
#include "utils/sortsupport.h"
#include "utils/date.h"
/*
* Defined in adt/
@ -907,6 +908,7 @@ extern char* output_text_to_cstring(const text* t);
extern char* output_int32_to_cstring(int32 value);
extern char* output_int64_to_cstring(int64 value);
extern char* output_int128_to_cstring(int128 value);
extern char* output_date_out(DateADT date);
extern void text_to_cstring_buffer(const text* src, char* dst, size_t dst_len);
extern int text_instr_3args(text* textStr, text* textStrToSearch, int32 beginIndex);
extern int text_instr_4args(text* textStr, text* textStrToSearch, int32 beginIndex, int occurTimes);