You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-30 19:23:07 +03:00
MCOL-641 Work of Ivan Zuniga on basic read and write support for Binary16
This commit is contained in:
committed by
Roman Nozdrin
parent
d943beb445
commit
32f6167067
@ -123,7 +123,9 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent,
|
||||
newFile = false;
|
||||
Column newCol;
|
||||
unsigned char buf[BYTE_PER_BLOCK];
|
||||
|
||||
unsigned char* curVal;
|
||||
int64_t emptyVal = getEmptyRowValue(column.colDataType, column.colWidth); // Seems is ok have it here and just once
|
||||
|
||||
if (useStartingExtent)
|
||||
{
|
||||
// ZZ. For insert select, skip the hwm block and start inserting from the next block
|
||||
@ -137,10 +139,10 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent,
|
||||
|
||||
if ( rc != NO_ERROR)
|
||||
return rc;
|
||||
|
||||
for (j = 0; j < totalRowPerBlock; j++)
|
||||
|
||||
for (j = 0, curVal = buf; j < totalRowPerBlock; j++, curVal += column.colWidth)
|
||||
{
|
||||
if (isEmptyRow(buf, j, column))
|
||||
if (isEmptyRow((uint64_t*)curVal, emptyVal, column.colWidth))
|
||||
{
|
||||
rowIdArray[counter] = getRowId(hwm, column.colWidth, j);
|
||||
rowsallocated++;
|
||||
@ -192,9 +194,9 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent,
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < totalRowPerBlock; j++)
|
||||
for (j = 0, curVal = buf; j < totalRowPerBlock; j++, curVal += column.colWidth)
|
||||
{
|
||||
if (isEmptyRow(buf, j, column))
|
||||
if (isEmptyRow((uint64_t*)curVal, emptyVal, column.colWidth))
|
||||
{
|
||||
rowIdArray[counter] = getRowId(hwm, column.colWidth, j);
|
||||
rowsallocated++;
|
||||
@ -492,9 +494,9 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent,
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < totalRowPerBlock; j++)
|
||||
for (j = 0, curVal = buf; j < totalRowPerBlock; j++, curVal += column.colWidth)
|
||||
{
|
||||
if (isEmptyRow(buf, j, column))
|
||||
if (isEmptyRow((uint64_t*)curVal, emptyVal, column.colWidth)) // Why to check it if beacause line 483 is always true ?
|
||||
{
|
||||
rowIdArray[counter] = getRowId(newHwm, column.colWidth, j);
|
||||
rowsallocated++;
|
||||
@ -533,9 +535,9 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent,
|
||||
}
|
||||
}
|
||||
|
||||
for (j = 0; j < totalRowPerBlock; j++)
|
||||
for (j = 0, curVal = buf; j < totalRowPerBlock; j++, curVal += column.colWidth)
|
||||
{
|
||||
if (isEmptyRow(buf, j, column))
|
||||
if (isEmptyRow((uint64_t*)curVal, emptyVal, column.colWidth))
|
||||
{
|
||||
rowIdArray[counter] = getRowId(newHwm, newCol.colWidth, j);
|
||||
rowsallocated++;
|
||||
@ -1064,7 +1066,7 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi
|
||||
startColFbo++;
|
||||
colBufOffset = 0;
|
||||
}
|
||||
|
||||
|
||||
while (((refBufOffset + refCol.colWidth) <= BYTE_PER_BLOCK) &&
|
||||
((colBufOffset + column.colWidth) <= BYTE_PER_BLOCK))
|
||||
{
|
||||
@ -1080,7 +1082,8 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi
|
||||
}
|
||||
else if (column.compressionType != 0) //@Bug 3866, fill the empty row value for compressed chunk
|
||||
{
|
||||
memcpy(colBuf + colBufOffset, &emptyVal, column.colWidth);
|
||||
for(int b = 0, w = column.colWidth; b < column.colWidth; b += 8, w = 8) //FIXME for no loop!
|
||||
memcpy(colBuf + colBufOffset + b, &emptyVal, w);
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
@ -1405,18 +1408,39 @@ void ColumnOp::initColumn(Column& column) const
|
||||
* RETURN:
|
||||
* true if success, false otherwise
|
||||
***********************************************************/
|
||||
bool ColumnOp::isEmptyRow(unsigned char* buf, int offset, const Column& column)
|
||||
|
||||
// It is called at just 4 places on allocRowId() but all the time inside extend scanning loops
|
||||
inline bool ColumnOp::isEmptyRow(uint64_t* curVal, uint64_t emptyVal, const int colWidth)
|
||||
{
|
||||
bool emptyFlag = true;
|
||||
uint64_t curVal, emptyVal;
|
||||
//Calling it here makes calling it "i" times from the calling loop at allocRowId()
|
||||
//uint64_t emptyVal = getEmptyRowValue(column.colDataType, column.colWidth);
|
||||
|
||||
// No need for it if change param type.. just been lazy to add extra castings
|
||||
//uint64_t &emptyVal = column.emptyVal;
|
||||
|
||||
//no need to multiply over and over if just increment the pointer on the caller
|
||||
//uint64_t *curVal = (uint64_t*)(buf + offset * column.colWidth);
|
||||
|
||||
memcpy(&curVal, buf + offset * column.colWidth, column.colWidth);
|
||||
emptyVal = getEmptyRowValue(column.colDataType, column.colWidth);
|
||||
switch(colWidth){
|
||||
case 1:
|
||||
return *(uint8_t*)curVal == emptyVal;
|
||||
|
||||
if (/*curVal != emptyVal*/memcmp(&curVal, &emptyVal, column.colWidth))
|
||||
emptyFlag = false;
|
||||
|
||||
return emptyFlag;
|
||||
case 2:
|
||||
return *(uint16_t*)curVal == emptyVal;
|
||||
|
||||
case 4:
|
||||
return *(uint32_t*)curVal == emptyVal;
|
||||
|
||||
case 8:
|
||||
return *curVal == emptyVal;
|
||||
|
||||
case 16:
|
||||
return ((curVal[0] == emptyVal) && (curVal[1] == emptyVal));
|
||||
|
||||
case 32:
|
||||
return ((curVal[0] == emptyVal) && (curVal[1] == emptyVal)
|
||||
&& (curVal[2] == emptyVal) && (curVal[3] == emptyVal));
|
||||
}
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
@ -1534,7 +1558,7 @@ void ColumnOp::setColParam(Column& column,
|
||||
column.colWidth = colWidth;
|
||||
column.colType = colType;
|
||||
column.colDataType = colDataType;
|
||||
|
||||
|
||||
column.dataFile.fid = dataFid;
|
||||
column.dataFile.fDbRoot = dbRoot;
|
||||
column.dataFile.fPartition = partition;
|
||||
@ -1662,6 +1686,12 @@ int ColumnOp::writeRow(Column& curCol, uint64_t totalRow, const RID* rowIdArray,
|
||||
if (!bDelete) pVal = &((uint64_t*) valArray)[i];
|
||||
break;
|
||||
|
||||
case WriteEngine::WR_BINARY:
|
||||
if (!bDelete) pVal = (uint8_t*) valArray + i * curCol.colWidth;
|
||||
|
||||
//pOldVal = (uint8_t*) oldValArray + i * curCol.colWidth;
|
||||
break;
|
||||
|
||||
default :
|
||||
if (!bDelete) pVal = &((int*) valArray)[i];
|
||||
break;
|
||||
@ -1669,7 +1699,7 @@ int ColumnOp::writeRow(Column& curCol, uint64_t totalRow, const RID* rowIdArray,
|
||||
|
||||
if (bDelete)
|
||||
{
|
||||
emptyVal = getEmptyRowValue(curCol.colDataType, curCol.colWidth);
|
||||
emptyVal = getEmptyRowValue(curCol.colDataType, curCol.colWidth);
|
||||
pVal = &emptyVal;
|
||||
}
|
||||
|
||||
@ -1852,7 +1882,8 @@ int ColumnOp::writeRows(Column& curCol, uint64_t totalRow, const RIDList& ridLis
|
||||
}
|
||||
|
||||
// This is the write stuff
|
||||
writeBufValue(dataBuf + dataBio, pVal, curCol.colWidth);
|
||||
for(int b = 0, w = curCol.colWidth > 8 ? 8 : curCol.colWidth; b < curCol.colWidth; b += 8) //FIXME for no loop
|
||||
writeBufValue(dataBuf + dataBio + b, pVal, w);
|
||||
|
||||
i++;
|
||||
|
||||
|
@ -220,7 +220,7 @@ public:
|
||||
/**
|
||||
* @brief Check whether it is an empty row
|
||||
*/
|
||||
EXPORT virtual bool isEmptyRow(unsigned char* buf, int offset, const Column& column);
|
||||
EXPORT virtual bool isEmptyRow(uint64_t* curVal, uint64_t emptyVal, const int colWidth);
|
||||
|
||||
/**
|
||||
* @brief Check whether it is a valid column
|
||||
|
@ -388,6 +388,15 @@ void WriteEngineWrapper::convertValue(const ColType colType, void* value, boost:
|
||||
memcpy(value, &val, size);
|
||||
}
|
||||
break;
|
||||
|
||||
case WriteEngine::WR_BINARY:
|
||||
{
|
||||
char val = boost::any_cast<char>(data);
|
||||
//TODO:FIXME how to determine size ? 16, 32,48 ?
|
||||
size = 16;
|
||||
memcpy(value, &val, size);
|
||||
}
|
||||
break;
|
||||
|
||||
} // end of switch (colType)
|
||||
} /*@convertValue - The base for converting values */
|
||||
@ -492,6 +501,12 @@ void WriteEngineWrapper::convertValue(const ColType colType, void* valArray, con
|
||||
case WriteEngine::WR_TOKEN:
|
||||
((Token*)valArray)[pos] = boost::any_cast<Token>(data);
|
||||
break;
|
||||
|
||||
case WriteEngine::WR_BINARY:
|
||||
curStr = boost::any_cast<string>(data);
|
||||
memcpy((char*)valArray + pos * curStr.length(), curStr.c_str(), curStr.length());
|
||||
break;
|
||||
|
||||
} // end of switch (colType)
|
||||
}
|
||||
else
|
||||
@ -557,6 +572,16 @@ void WriteEngineWrapper::convertValue(const ColType colType, void* valArray, con
|
||||
case WriteEngine::WR_TOKEN:
|
||||
data = ((Token*)valArray)[pos];
|
||||
break;
|
||||
|
||||
case WriteEngine::WR_BINARY :
|
||||
{
|
||||
char tmp[16];
|
||||
//TODO:FIXME how to determine size ? 16, 32,48 ?
|
||||
memcpy(tmp, (char*)valArray + pos * 16, 16);
|
||||
curStr = tmp;
|
||||
data = curStr;
|
||||
}
|
||||
break;
|
||||
} // end of switch (colType)
|
||||
} // end of if
|
||||
}
|
||||
@ -3234,7 +3259,7 @@ int WriteEngineWrapper::insertColumnRec_Single(const TxnID& txnid,
|
||||
}
|
||||
|
||||
bool newFile;
|
||||
|
||||
cout << "Datafile " << curCol.dataFile.fSegFileName << endl;
|
||||
#ifdef PROFILE
|
||||
timer.start("allocRowId");
|
||||
#endif
|
||||
@ -5130,6 +5155,10 @@ int WriteEngineWrapper::writeColumnRec(const TxnID& txnid,
|
||||
case WriteEngine::WR_TOKEN:
|
||||
valArray = (Token*) calloc(sizeof(Token), totalRow1);
|
||||
break;
|
||||
|
||||
case WriteEngine::WR_BINARY:
|
||||
valArray = calloc(colStructList[i].colWidth, totalRow1);
|
||||
break;
|
||||
}
|
||||
|
||||
// convert values to valArray
|
||||
@ -5349,6 +5378,11 @@ int WriteEngineWrapper::writeColumnRecBinary(const TxnID& txnid,
|
||||
tmp16 = curValue;
|
||||
((uint16_t*)valArray)[j] = tmp16;
|
||||
break;
|
||||
|
||||
case WriteEngine::WR_BINARY:
|
||||
((uint64_t*)valArray)[j] = curValue; //FIXME maybe
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -5492,6 +5526,10 @@ int WriteEngineWrapper::writeColumnRecBinary(const TxnID& txnid,
|
||||
tmp16 = curValue;
|
||||
((uint16_t*)valArray)[j] = tmp16;
|
||||
break;
|
||||
|
||||
case WriteEngine::WR_BINARY:
|
||||
((uint64_t*)valArray)[j] = curValue; // FIXME maybe
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -5775,6 +5813,9 @@ int WriteEngineWrapper::writeColumnRec(const TxnID& txnid,
|
||||
case WriteEngine::WR_TOKEN:
|
||||
valArray = (Token*) calloc(sizeof(Token), 1);
|
||||
break;
|
||||
case WriteEngine::WR_BINARY:
|
||||
valArray = (char*) calloc(sizeof(char), curColStruct.colWidth); //FIXME maybe
|
||||
break;
|
||||
}
|
||||
|
||||
// convert values to valArray
|
||||
|
Reference in New Issue
Block a user