You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-08-01 06:46:55 +03:00
Remove variable-length arrays (-Wvla)
This commit is contained in:
100
utils/common/vlarray.h
Normal file
100
utils/common/vlarray.h
Normal file
@ -0,0 +1,100 @@
|
||||
/* Copyright (C) 2020 MariaDB Corporation
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; version 2 of
|
||||
the License.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
MA 02110-1301, USA. */
|
||||
#ifndef UTILS_COMMON_VLARRAY_H
|
||||
#define UTILS_COMMON_VLARRAY_H
|
||||
|
||||
namespace utils {
|
||||
|
||||
template <typename T, size_t SIZE=64>
|
||||
class VLArray
|
||||
{
|
||||
public:
|
||||
VLArray(size_t sz) :
|
||||
sz(sz),
|
||||
stack_storage(NULL),
|
||||
dyn_storage(NULL),
|
||||
ptr(NULL)
|
||||
{
|
||||
if (sz > SIZE) {
|
||||
dyn_storage = new T[sz];
|
||||
ptr = dyn_storage;
|
||||
} else {
|
||||
stack_storage = new (stack) T[sz];
|
||||
ptr = stack_storage;
|
||||
}
|
||||
}
|
||||
|
||||
VLArray(size_t sz, const T& initval) : VLArray(sz)
|
||||
{
|
||||
for (size_t i= 0; i < sz; ++i)
|
||||
ptr[i]= initval;
|
||||
}
|
||||
|
||||
VLArray(const VLArray&) = delete;
|
||||
VLArray(VLArray&&) = delete;
|
||||
VLArray& operator=(const VLArray&) = delete;
|
||||
VLArray& operator=(VLArray&&) = delete;
|
||||
|
||||
~VLArray() {
|
||||
if (dyn_storage) {
|
||||
delete [] dyn_storage;
|
||||
} else {
|
||||
// we cannot use `delete [] stack_storage` here so call d-tors explicitly
|
||||
if (!std::is_trivially_destructible<T>::value) {
|
||||
for (size_t i = 0; i < sz; ++i)
|
||||
stack_storage[i].~T();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t size() const { return sz; }
|
||||
const T* data() const { return ptr; }
|
||||
T* data() { return ptr; }
|
||||
|
||||
const T& operator[](size_t i) const { return ptr[i]; }
|
||||
T& operator[](size_t i) { return ptr[i]; }
|
||||
|
||||
const T& at(size_t i) const {
|
||||
if (i >= sz) {
|
||||
throw std::out_of_range("index out of range: " + std::to_string(i) +
|
||||
" >= size " + std::to_string(sz));
|
||||
}
|
||||
return ptr[i];
|
||||
}
|
||||
|
||||
T& at(size_t i) {
|
||||
if (i >= sz) {
|
||||
throw std::out_of_range("index out of range: " + std::to_string(i) +
|
||||
" >= size " + std::to_string(sz));
|
||||
}
|
||||
return ptr[i];
|
||||
}
|
||||
|
||||
operator const T* () const { return ptr; }
|
||||
operator T* () { return ptr; }
|
||||
|
||||
private:
|
||||
const size_t sz;
|
||||
alignas(T) char stack[SIZE * sizeof(T)];
|
||||
T* stack_storage;
|
||||
T* dyn_storage;
|
||||
T* ptr;
|
||||
};
|
||||
|
||||
} // namespace utils
|
||||
|
||||
#endif // UTILS_COMMON_VLARRAY_H
|
@ -40,6 +40,8 @@ using namespace logging;
|
||||
|
||||
#include "collation.h"
|
||||
|
||||
#include "vlarray.h"
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
@ -89,7 +91,7 @@ string Func_char::getStrVal(Row& row,
|
||||
CalpontSystemCatalog::ColType& ct)
|
||||
{
|
||||
const int BUF_SIZE = 4 * parm.size();
|
||||
char buf[BUF_SIZE];
|
||||
utils::VLArray<char, 1024> buf(BUF_SIZE);
|
||||
buf[0]= 0;
|
||||
char* pBuf = buf;
|
||||
CHARSET_INFO* cs = ct.getCharset();
|
||||
|
@ -75,7 +75,7 @@ std::string Func_strcmp::getStrVal(rowgroup::Row& row,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& type)
|
||||
{
|
||||
uint64_t val = getIntVal(row, fp, isNull, type);
|
||||
int64_t val = getIntVal(row, fp, isNull, type);
|
||||
|
||||
if (val > 0)
|
||||
return string("1");
|
||||
|
@ -36,6 +36,7 @@
|
||||
#endif
|
||||
|
||||
#include "installdir.h"
|
||||
#include "vlarray.h"
|
||||
|
||||
|
||||
using namespace std;
|
||||
@ -246,7 +247,7 @@ void IDBPolicy::configIDBPolicy()
|
||||
// The feature is used in the FileOp code and enabled by default.
|
||||
char configSectionPref[] = "DBRoot";
|
||||
int confSectionLen = sizeof(configSectionPref)+oam::MAX_MODULE_ID_SIZE;
|
||||
char configSection[confSectionLen];
|
||||
utils::VLArray<char, 1024> configSection(confSectionLen);
|
||||
|
||||
IDBPolicy::init( idblog, bUseRdwrMemBuffer, hdfsRdwrScratch, hdfsRdwrBufferMaxSize );
|
||||
s_configed = true;
|
||||
@ -283,8 +284,8 @@ void IDBPolicy::configIDBPolicy()
|
||||
oam::DBRootConfigList::iterator dbRootIter = dbRootVec.begin();
|
||||
for(; dbRootIter != dbRootVec.end(); dbRootIter++)
|
||||
{
|
||||
::memset(configSection + sizeof(configSectionPref), 0, oam::MAX_MODULE_ID_SIZE);
|
||||
rc = snprintf(configSection, confSectionLen, "%s%d", configSectionPref, *dbRootIter);
|
||||
::memset(configSection.data() + sizeof(configSectionPref), 0, oam::MAX_MODULE_ID_SIZE);
|
||||
rc = snprintf(configSection.data(), confSectionLen, "%s%d", configSectionPref, *dbRootIter);
|
||||
// gcc 8.2 warnings
|
||||
if ( rc < 0 || rc >= confSectionLen)
|
||||
{
|
||||
@ -292,7 +293,7 @@ void IDBPolicy::configIDBPolicy()
|
||||
oss << "IDBPolicy::configIDBPolicy: failed to parse DBRootX section.";
|
||||
throw runtime_error(oss.str());
|
||||
}
|
||||
string setting = cf->getConfig(configSection, "PreallocSpace");
|
||||
string setting = cf->getConfig(configSection.data(), "PreallocSpace");
|
||||
|
||||
if ( setting.length() != 0 )
|
||||
{
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "hasher.h"
|
||||
#include "lbidlist.h"
|
||||
#include "spinlock.h"
|
||||
#include "vlarray.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace rowgroup;
|
||||
@ -279,8 +280,8 @@ void TupleJoiner::bucketsToTables(buckets_t *buckets, hash_table_t *tables)
|
||||
|
||||
void TupleJoiner::um_insertTypeless(uint threadID, uint rowCount, Row &r)
|
||||
{
|
||||
TypelessData td[rowCount];
|
||||
vector<pair<TypelessData, Row::Pointer> > v[bucketCount];
|
||||
utils::VLArray<TypelessData> td(rowCount);
|
||||
utils::VLArray<vector<pair<TypelessData, Row::Pointer> > > v(bucketCount);
|
||||
uint i;
|
||||
FixedAllocator *alloc = &storedKeyAlloc[threadID];
|
||||
|
||||
@ -298,7 +299,7 @@ void TupleJoiner::um_insertTypeless(uint threadID, uint rowCount, Row &r)
|
||||
|
||||
void TupleJoiner::um_insertLongDouble(uint rowCount, Row &r)
|
||||
{
|
||||
vector<pair<long double, Row::Pointer> > v[bucketCount];
|
||||
utils::VLArray<vector<pair<long double, Row::Pointer> > > v(bucketCount);
|
||||
uint i;
|
||||
uint smallKeyColumn = smallKeyColumns[0];
|
||||
|
||||
@ -318,7 +319,7 @@ void TupleJoiner::um_insertInlineRows(uint rowCount, Row &r)
|
||||
{
|
||||
uint i;
|
||||
int64_t smallKey;
|
||||
vector<pair<int64_t, uint8_t *> > v[bucketCount];
|
||||
utils::VLArray<vector<pair<int64_t, uint8_t *> > > v(bucketCount);
|
||||
uint smallKeyColumn = smallKeyColumns[0];
|
||||
|
||||
for (i = 0; i < rowCount; i++, r.nextRow())
|
||||
@ -340,7 +341,7 @@ void TupleJoiner::um_insertStringTable(uint rowCount, Row &r)
|
||||
{
|
||||
int64_t smallKey;
|
||||
uint i;
|
||||
vector<pair<int64_t, Row::Pointer> > v[bucketCount];
|
||||
utils::VLArray<vector<pair<int64_t, Row::Pointer> > > v(bucketCount);
|
||||
uint smallKeyColumn = smallKeyColumns[0];
|
||||
|
||||
for (i = 0; i < rowCount; i++, r.nextRow())
|
||||
@ -810,7 +811,7 @@ void TupleJoiner::setInUM()
|
||||
size = rows.size();
|
||||
size_t chunkSize = ((size / numCores) + 1 < 50000 ? 50000 : (size / numCores) + 1); // don't start a thread to process < 50k rows
|
||||
|
||||
uint64_t jobs[numCores];
|
||||
utils::VLArray<uint64_t> jobs(numCores);
|
||||
i = 0;
|
||||
for (size_t firstRow = 0; i < (uint) numCores && firstRow < size; i++, firstRow += chunkSize)
|
||||
jobs[i] = jobstepThreadPool->invoke([this, firstRow, chunkSize, size] {
|
||||
@ -862,7 +863,7 @@ void TupleJoiner::setInUM(vector<RGData> &rgs)
|
||||
size = rgs.size();
|
||||
size_t chunkSize = ((size / numCores) + 1 < 10 ? 10 : (size / numCores) + 1); // don't issue jobs for < 10 rowgroups
|
||||
|
||||
uint64_t jobs[numCores];
|
||||
utils::VLArray<uint64_t> jobs(numCores);
|
||||
i = 0;
|
||||
for (size_t firstRow = 0; i < (uint) numCores && firstRow < size; i++, firstRow += chunkSize)
|
||||
jobs[i] = jobstepThreadPool->invoke([this, firstRow, chunkSize, size, i, &rgs] {
|
||||
|
@ -50,6 +50,7 @@
|
||||
#include "rowaggregation.h"
|
||||
#include "calpontsystemcatalog.h"
|
||||
#include "utils_utf8.h"
|
||||
#include "vlarray.h"
|
||||
|
||||
#include "collation.h"
|
||||
|
||||
@ -1935,8 +1936,8 @@ void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut,
|
||||
{
|
||||
uint32_t paramCount = fRGContext.getParameterCount();
|
||||
// The vector of parameters to be sent to the UDAF
|
||||
mcsv1sdk::ColumnDatum valsIn[paramCount];
|
||||
uint32_t dataFlags[paramCount];
|
||||
utils::VLArray<mcsv1sdk::ColumnDatum> valsIn(paramCount);
|
||||
utils::VLArray<uint32_t> dataFlags(paramCount);
|
||||
execplan::ConstantColumn* cc;
|
||||
bool bIsNull = false;
|
||||
execplan::CalpontSystemCatalog::ColDataType colDataType;
|
||||
@ -2204,6 +2205,7 @@ void RowAggregation::doUDAF(const Row& rowIn, int64_t colIn, int64_t colOut,
|
||||
++funcColsIdx;
|
||||
colIn = fFunctionCols[funcColsIdx]->fInputColumnIndex;
|
||||
colOut = fFunctionCols[funcColsIdx]->fOutputColumnIndex;
|
||||
(void)colOut;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -49,6 +49,8 @@ using namespace joblist;
|
||||
|
||||
#include "wf_udaf.h"
|
||||
|
||||
#include "vlarray.h"
|
||||
|
||||
|
||||
namespace windowfunction
|
||||
{
|
||||
@ -118,7 +120,7 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
|
||||
getContext().setContextFlag(mcsv1sdk::CONTEXT_IS_ANALYTIC);
|
||||
|
||||
// Put the parameter metadata (type, scale, precision) into valsIn
|
||||
mcsv1sdk::ColumnDatum valsIn[getContext().getParameterCount()];
|
||||
utils::VLArray<mcsv1sdk::ColumnDatum> valsIn(getContext().getParameterCount());
|
||||
ConstantColumn* cc = NULL;
|
||||
|
||||
for (uint32_t i = 0; i < getContext().getParameterCount(); ++i)
|
||||
@ -141,6 +143,7 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
|
||||
}
|
||||
}
|
||||
|
||||
utils::VLArray<uint32_t> flags(getContext().getParameterCount());
|
||||
for (int64_t i = b; i < e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
@ -149,7 +152,6 @@ bool WF_udaf::dropValues(int64_t b, int64_t e)
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
|
||||
// NULL flags
|
||||
uint32_t flags[getContext().getParameterCount()];
|
||||
bool bSkipIt = false;
|
||||
|
||||
for (uint32_t k = 0; k < getContext().getParameterCount(); ++k)
|
||||
@ -786,7 +788,7 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
||||
getContext().setContextFlag(mcsv1sdk::CONTEXT_IS_ANALYTIC);
|
||||
|
||||
// Put the parameter metadata (type, scale, precision) into valsIn
|
||||
mcsv1sdk::ColumnDatum valsIn[getContext().getParameterCount()];
|
||||
utils::VLArray<mcsv1sdk::ColumnDatum> valsIn(getContext().getParameterCount());
|
||||
ConstantColumn* cc = NULL;
|
||||
|
||||
for (uint32_t i = 0; i < getContext().getParameterCount(); ++i)
|
||||
@ -815,7 +817,7 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
||||
getContext().clearContextFlag(mcsv1sdk::CONTEXT_HAS_CURRENT_ROW);
|
||||
|
||||
bool bSkipIt = false;
|
||||
|
||||
utils::VLArray<uint32_t> flags(getContext().getParameterCount());
|
||||
for (int64_t i = b; i <= e; i++)
|
||||
{
|
||||
if (i % 1000 == 0 && fStep->cancelled())
|
||||
@ -824,7 +826,6 @@ void WF_udaf::operator()(int64_t b, int64_t e, int64_t c)
|
||||
fRow.setData(getPointer(fRowData->at(i)));
|
||||
|
||||
// NULL flags
|
||||
uint32_t flags[getContext().getParameterCount()];
|
||||
bSkipIt = false;
|
||||
|
||||
for (uint32_t k = 0; k < getContext().getParameterCount(); ++k)
|
||||
|
Reference in New Issue
Block a user