From 1575f26d57c95b138f4c6dfb474b82d99bdb700c Mon Sep 17 00:00:00 2001 From: Eureka Date: Wed, 27 Nov 2024 17:32:10 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=8C=E5=88=97=E8=9E=8D=E5=90=88=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=88=97=E6=9C=80=E5=A4=A7=E9=95=BF=E5=BA=A6=E9=99=90?= =?UTF-8?q?=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gausskernel/storage/htap/imcs_ctlg.cpp | 30 ++++++++++++++++++---- src/include/access/htap/imcs_ctlg.h | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/gausskernel/storage/htap/imcs_ctlg.cpp b/src/gausskernel/storage/htap/imcs_ctlg.cpp index f5a38f88e..9a1bbbdd5 100644 --- a/src/gausskernel/storage/htap/imcs_ctlg.cpp +++ b/src/gausskernel/storage/htap/imcs_ctlg.cpp @@ -112,6 +112,24 @@ static FORCE_INLINE void DeDuplicateAttrNumber(int2* sortedAttsNums, int *colNum *colNum = curr + 1; } +void CheckForAttrLen(Oid relOid, FormData_pg_attribute* att) +{ + if (att->attlen > 0) { + /* Fixed-length types are never over maxlen */ + return; + } + + int32 maxlen = type_maximum_size(att->atttypid, att->atttypmod); + if (maxlen < 0) { + ereport(ERROR, (errmsg("Max attr length of Rel [%d]: col [%s] is unknow, not supported by imcstore.", + relOid, att->attname.data))); + } + if (maxlen > MAX_IMCS_COL_LENGTH) { + ereport(ERROR, (errmsg("Max attr length [%d] of Rel [%d]: col [%s] exceeded imcs col max length: %d.", + maxlen, relOid, att->attname.data, MAX_IMCS_COL_LENGTH))); + } +} + void CheckImcsSupportForDataTypes(Relation rel, List* colList, int2vector* &imcsAttsNum, int* imcsNatts) { /* check if specify cols, yes when colCnt != 0 */ @@ -124,6 +142,7 @@ void CheckImcsSupportForDataTypes(Relation rel, List* colList, int2vector* &imcs imcsColCnt++; } + FormData_pg_attribute *relAtts = rel->rd_att->attrs; /* only populate specified cols */ if (imcsColCnt != 0) { attsNums = (int2*)palloc(sizeof(int2*) * imcsColCnt); @@ -133,7 +152,8 @@ void CheckImcsSupportForDataTypes(Relation rel, List* colList, int2vector* &imcs if (!AttributeNumberIsValid(attnumber)) { ereport(ERROR, (errmsg("Col %s not exist in rel %d.", colName, relOid))); } - CheckForDataType(get_atttype(relOid, attnumber), get_atttypmod(relOid, attnumber)); + CheckForDataType(relAtts[attnumber - 1].atttypid, relAtts[attnumber - 1].atttypmod); + CheckForAttrLen(relOid, &relAtts[attnumber - 1]); *(attsNums + i) = attnumber; i++; } @@ -141,13 +161,13 @@ void CheckImcsSupportForDataTypes(Relation rel, List* colList, int2vector* &imcs DeDuplicateAttrNumber(attsNums, &imcsColCnt); } else { /* populate all cols */ - FormData_pg_attribute *relAtts = rel->rd_att->attrs; - int atts = rel->rd_att->natts; - for (int i = 0; i < atts; i++) { + int natts = rel->rd_att->natts; + for (i = 0; i < natts; i++) { if (relAtts[i].attisdropped) { continue; } CheckForDataType(relAtts[i].atttypid, relAtts[i].atttypmod); + CheckForAttrLen(relOid, &relAtts[i]); imcsColCnt++; } @@ -159,7 +179,7 @@ void CheckImcsSupportForDataTypes(Relation rel, List* colList, int2vector* &imcs int j = 0; attsNums = (int2*)palloc(sizeof(int2*) * imcsColCnt); - for (int i = 0; i < atts; i++) { + for (i = 0; i < natts; i++) { *(attsNums + j) = relAtts[i].attnum; j++; } diff --git a/src/include/access/htap/imcs_ctlg.h b/src/include/access/htap/imcs_ctlg.h index f0fdfdb25..d40fc1a0d 100644 --- a/src/include/access/htap/imcs_ctlg.h +++ b/src/include/access/htap/imcs_ctlg.h @@ -33,6 +33,7 @@ #include "postmaster/bgworker.h" #define MAX_IMCS_PAGES_ONE_CU 1024 +#define MAX_IMCS_COL_LENGTH 8192 #define MAX_PARALLEL_WORK_NUMS 8 #define VIRTUAL_IMCS_CTID (-1) #define TYPE_IMCSTORED 1