diff --git a/dbcon/ddlpackage/serialize.cpp b/dbcon/ddlpackage/serialize.cpp index 622ee91c1..c6c165bd4 100644 --- a/dbcon/ddlpackage/serialize.cpp +++ b/dbcon/ddlpackage/serialize.cpp @@ -125,6 +125,8 @@ int AlterTableStatement::unserialize(ByteStream& bytestream) // read alter action list quadbyte action_count; bytestream >> action_count; + // Reserve space for actions + fActions.reserve(action_count); for (unsigned int i = 0; i < action_count; i++) { @@ -749,6 +751,8 @@ int AtaDropColumns::unserialize(ByteStream& bytestream) quadbyte count; bytestream >> count; + // Reserve space for columns + fColumns.reserve(count); string colName; while (count--) @@ -1628,6 +1632,8 @@ int TableDef::unserialize(ByteStream& bytestream) // read column constraint list quadbyte count; bytestream >> count; + // Reserve space for constraints + fConstraints.reserve(count); TableConstraintDef* constraint; while (count-- > 0) diff --git a/dbcon/ddlpackageproc/ddlindexpopulator.cpp b/dbcon/ddlpackageproc/ddlindexpopulator.cpp index 734aa3ff1..ab0544836 100644 --- a/dbcon/ddlpackageproc/ddlindexpopulator.cpp +++ b/dbcon/ddlpackageproc/ddlindexpopulator.cpp @@ -148,6 +148,9 @@ void DDLIndexPopulator::makeCsep(CalpontSelectExecutionPlan& csep) string tableName(fTable.fSchema + "." + fTable.fName + "."); ColumnNameList::const_iterator cend = fColNames.end(); + // Reserve space for column list and OIDs + colList.reserve(fColNames.size()); + fOidList.reserve(fColNames.size()); for (ColumnNameList::const_iterator cname = fColNames.begin(); cname != cend; ++cname) { @@ -199,6 +202,8 @@ void DDLIndexPopulator::addColumnData(const execplan::ColumnResult* cr, const CalpontSystemCatalog::ColType colType, int added) { WriteEngine::IdxTupleList tupleList; + // Reserve space for tuples + tupleList.reserve(cr->dataCount()); WriteEngine::IdxTuple tuple; for (int i = 0; i < cr->dataCount(); ++i) diff --git a/dbcon/ddlpackageproc/ddlpackageprocessor.cpp b/dbcon/ddlpackageproc/ddlpackageprocessor.cpp index ef37fa3fa..5abb160b9 100644 --- a/dbcon/ddlpackageproc/ddlpackageprocessor.cpp +++ b/dbcon/ddlpackageproc/ddlpackageprocessor.cpp @@ -459,6 +459,11 @@ void DDLPackageProcessor::flushPrimprocCache(std::vectorsize; + blockList.reserve(totalSize); for (it = lbidRanges.begin(); it != lbidRanges.end(); it++) { diff --git a/dbcon/ddlpackageproc/droptableprocessor.cpp b/dbcon/ddlpackageproc/droptableprocessor.cpp index b8d67fe7e..32e822058 100644 --- a/dbcon/ddlpackageproc/droptableprocessor.cpp +++ b/dbcon/ddlpackageproc/droptableprocessor.cpp @@ -315,6 +315,8 @@ DropTableProcessor::DDLResult DropTableProcessor::processPackageInternal(ddlpack Oam oam; // Save qualified tablename, all column, dictionary OIDs, and transaction ID into a file in ASCII format + // Reserve space for OIDs + oidList.reserve(tableColRidList.size() + dictOIDList.size()); for (unsigned i = 0; i < tableColRidList.size(); i++) { if (tableColRidList[i].objnum > 3000) @@ -965,6 +967,9 @@ TruncTableProcessor::DDLResult TruncTableProcessor::processPackageInternal(ddlpa dictOIDList = systemCatalogPtr->dictOIDs(userTableName); + // Reserve space for OIDs (columns + aux column + dictionaries) + columnOidList.reserve(tableColRidList.size() + 1); + allOidList.reserve(tableColRidList.size() + 1 + dictOIDList.size()); for (unsigned i = 0; i < tableColRidList.size(); i++) { if (tableColRidList[i].objnum > 3000) diff --git a/dbcon/dmlpackage/deletedmlpackage.cpp b/dbcon/dmlpackage/deletedmlpackage.cpp index 3e1c875f9..bbc9836d2 100644 --- a/dbcon/dmlpackage/deletedmlpackage.cpp +++ b/dbcon/dmlpackage/deletedmlpackage.cpp @@ -154,6 +154,8 @@ int DeleteDMLPackage::buildFromBuffer(std::string& buffer, int /*columns*/, int initializeTable(); std::vector dataList; + // Reserve space for row IDs + dataList.reserve(rows); typedef boost::tokenizer > tokenizer; boost::char_separator sep(":"); tokenizer tokens(buffer, sep); diff --git a/dbcon/dmlpackage/updatedmlpackage.cpp b/dbcon/dmlpackage/updatedmlpackage.cpp index 325b44220..bdac885f9 100644 --- a/dbcon/dmlpackage/updatedmlpackage.cpp +++ b/dbcon/dmlpackage/updatedmlpackage.cpp @@ -138,6 +138,8 @@ int UpdateDMLPackage::buildFromSqlStatement(SqlStatement& sqlStatement) // Push one row always and let the filter happen on the proc side. Row* rowPtr = new Row(); + // Reserve space for columns + rowPtr->get_ColumnList().reserve(updateStmt.fColAssignmentListPtr->size()); ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin(); while (iter != updateStmt.fColAssignmentListPtr->end()) @@ -176,6 +178,8 @@ int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows initializeTable(); std::vector dataList; + // Reserve space: each row has rowid + columns * 2 (name + value) + dataList.reserve(rows * (1 + columns * 2)); typedef boost::tokenizer > tokenizer; boost::char_separator sep(":,"); tokenizer tokens(buffer, sep); @@ -186,11 +190,15 @@ int UpdateDMLPackage::buildFromBuffer(std::string& buffer, int columns, int rows } int n = 0; + // Reserve space for rows + fTable->get_RowList().reserve(rows); for (int i = 0; i < rows; i++) { // get a new row Row* aRowPtr = new Row(); + // Reserve space for columns + aRowPtr->get_ColumnList().reserve(columns); std::string colName; std::string colValue; // get row ID from the buffer @@ -229,6 +237,8 @@ int UpdateDMLPackage::buildFromMysqlBuffer(ColNameList& colNameList, TableValues initializeTable(); Row* aRowPtr = new Row(); + // Reserve space for columns + aRowPtr->get_ColumnList().reserve(columns); std::string colName; ColValuesList colValList; @@ -259,6 +269,8 @@ void UpdateDMLPackage::buildUpdateFromMysqlBuffer(UpdateSqlStatement& updateStmt // Push one row always and let the filter happen on the proc side. Row* rowPtr = new Row(); + // Reserve space for columns + rowPtr->get_ColumnList().reserve(updateStmt.fColAssignmentListPtr->size()); ColumnAssignmentList::const_iterator iter = updateStmt.fColAssignmentListPtr->begin(); while (iter != updateStmt.fColAssignmentListPtr->end()) diff --git a/dbcon/execplan/calpontselectexecutionplan.cpp b/dbcon/execplan/calpontselectexecutionplan.cpp index 44d5feb4e..62e6cfcd5 100644 --- a/dbcon/execplan/calpontselectexecutionplan.cpp +++ b/dbcon/execplan/calpontselectexecutionplan.cpp @@ -167,6 +167,7 @@ void CalpontSelectExecutionPlan::filterTokenList(FilterTokenList& filterTokenLis Parser parser; std::vector tokens; + tokens.reserve(filterTokenList.size()); Token t; for (unsigned int i = 0; i < filterTokenList.size(); i++) @@ -185,6 +186,7 @@ void CalpontSelectExecutionPlan::havingTokenList(const FilterTokenList& havingTo Parser parser; std::vector tokens; + tokens.reserve(havingTokenList.size()); Token t; for (unsigned int i = 0; i < havingTokenList.size(); i++) diff --git a/dbcon/execplan/calpontsystemcatalog.cpp b/dbcon/execplan/calpontsystemcatalog.cpp index 118fe1f6e..a839110db 100644 --- a/dbcon/execplan/calpontsystemcatalog.cpp +++ b/dbcon/execplan/calpontsystemcatalog.cpp @@ -6335,6 +6335,13 @@ vector getAllSysCatOIDs() vector ret; CalpontSystemCatalog::OID oid; + // Reserve space for all OIDs from all system catalogs + size_t totalSize = (SYSTABLE_MAX - SYSTABLE_BASE - 1) + + (SYSCOLUMN_MAX - SYSCOLUMN_BASE - 1) + + (SYSTABLE_DICT_MAX - SYSTABLE_DICT_BASE - 1) + + (SYSCOLUMN_DICT_MAX - SYSCOLUMN_DICT_BASE - 1); + ret.reserve(totalSize); + for (oid = SYSTABLE_BASE + 1; oid < SYSTABLE_MAX; oid++) ret.push_back(oid); diff --git a/dbcon/joblist/jlf_tuplejoblist.cpp b/dbcon/joblist/jlf_tuplejoblist.cpp index 0296f6d60..7ec8f064f 100644 --- a/dbcon/joblist/jlf_tuplejoblist.cpp +++ b/dbcon/joblist/jlf_tuplejoblist.cpp @@ -246,10 +246,31 @@ void constructJoinedRowGroup(RowGroup& rg, uint32_t large, uint32_t prev, bool r if (root == false) // not root { vector& joinKeys = jobInfo.tableJoinMap[make_pair(large, prev)].fLeftKeys; + // Reserve space for vectors (estimate based on join keys + tables) + size_t estimatedSize = joinKeys.size() + tableSet.size() * 8; // rough estimate + pos.reserve(estimatedSize + 1); + oids.reserve(estimatedSize); + keys.reserve(estimatedSize); + scale.reserve(estimatedSize); + precision.reserve(estimatedSize); + types.reserve(estimatedSize); + csNums.reserve(estimatedSize); for (vector::iterator i = joinKeys.begin(); i != joinKeys.end(); i++) addColumnToRG(*i, pos, oids, keys, scale, precision, types, csNums, jobInfo); } + else + { + // Reserve space for vectors when root + size_t estimatedSize = tableSet.size() * 8; // rough estimate + pos.reserve(estimatedSize + 1); + oids.reserve(estimatedSize); + keys.reserve(estimatedSize); + scale.reserve(estimatedSize); + precision.reserve(estimatedSize); + types.reserve(estimatedSize); + csNums.reserve(estimatedSize); + } // -- followed by the columns in select or expression for (set::iterator i = tableSet.begin(); i != tableSet.end(); i++) @@ -347,6 +368,16 @@ void adjustLastStep(JobStepVector& querySteps, DeliveredTableMap& deliverySteps, vector csNums; pos.push_back(2); + // Reserve space for all vectors + size_t vSize = v.size(); + pos.reserve(vSize + 1); + oids.reserve(vSize); + keys.reserve(vSize); + types.reserve(vSize); + csNums.reserve(vSize); + scale.reserve(vSize); + precision.reserve(vSize); + for (unsigned i = 0; i < v.size(); i++) { pos.push_back(pos.back() + v[i].width); @@ -603,6 +634,16 @@ void addProjectStepsToBps(TableInfoMap::iterator& mit, BatchPrimitive* bps, JobI psv.insert(psv.end(), expSteps.begin(), expSteps.end()); // add expressions to project set seenCols; // columns already processed + // Reserve space for output rowgroup vectors (psv.size() + fjKeys is upper bound) + size_t estimatedSize = psv.size() + fjKeys.size(); + pos.reserve(estimatedSize + 1); + oids.reserve(estimatedSize); + keys.reserve(estimatedSize); + scale.reserve(estimatedSize); + precision.reserve(estimatedSize); + types.reserve(estimatedSize); + csNums.reserve(estimatedSize); + // for passthru conversion // passthru is disabled (default lastTupleId to -1) unless the TupleBPS::bop is BOP_AND. uint64_t lastTupleId = -1; @@ -1294,6 +1335,16 @@ bool combineJobStepsByTable(TableInfoMap::iterator& mit, JobInfo& jobInfo) vector csNums; pos.push_back(2); + // Reserve space for all vectors + size_t tisSize = tis.size(); + pos.reserve(tisSize + 1); + oids.reserve(tisSize); + keys.reserve(tisSize); + types.reserve(tisSize); + csNums.reserve(tisSize); + scale.reserve(tisSize); + precision.reserve(tisSize); + for (unsigned i = 0; i < tis.size(); i++) { pos.push_back(pos.back() + tis[i].width); diff --git a/dbcon/joblist/joblistfactory.cpp b/dbcon/joblist/joblistfactory.cpp index 5b833327d..37bc73fce 100644 --- a/dbcon/joblist/joblistfactory.cpp +++ b/dbcon/joblist/joblistfactory.cpp @@ -420,6 +420,7 @@ void preProcessFunctionOnAggregation(const vector& scs, const vec void checkReturnedColumns(CalpontSelectExecutionPlan* csep, JobInfo& jobInfo) { + jobInfo.nonConstCols.reserve(jobInfo.deliveredCols.size()); for (uint64_t i = 0; i < jobInfo.deliveredCols.size(); i++) { if (NULL == dynamic_cast(jobInfo.deliveredCols[i].get())) diff --git a/dbcon/joblist/tupleaggregatestep.cpp b/dbcon/joblist/tupleaggregatestep.cpp index 0473ee23b..02a014b91 100644 --- a/dbcon/joblist/tupleaggregatestep.cpp +++ b/dbcon/joblist/tupleaggregatestep.cpp @@ -994,6 +994,7 @@ void TupleAggregateStep::prep1PhaseAggregate(JobInfo& jobInfo, vector& // collect the projected column info, prepare for aggregation vector width; + width.reserve(keysProj.size()); map projColPosMap; for (uint64_t i = 0; i < keysProj.size(); i++) @@ -1004,6 +1005,7 @@ void TupleAggregateStep::prep1PhaseAggregate(JobInfo& jobInfo, vector& // for groupby column map groupbyMap; + groupBy.reserve(jobInfo.groupByColVec.size() + jobInfo.distinctColVec.size()); for (uint64_t i = 0; i < jobInfo.groupByColVec.size(); i++) { @@ -1030,6 +1032,16 @@ void TupleAggregateStep::prep1PhaseAggregate(JobInfo& jobInfo, vector& AGG_MAP aggFuncMap; uint64_t outIdx = 0; + // Reserve space for all aggregate vectors + oidsAgg.reserve(returnedColVec.size()); + keysAgg.reserve(returnedColVec.size()); + scaleAgg.reserve(returnedColVec.size()); + precisionAgg.reserve(returnedColVec.size()); + typeAgg.reserve(returnedColVec.size()); + csNumAgg.reserve(returnedColVec.size()); + widthAgg.reserve(returnedColVec.size()); + functionVec.reserve(returnedColVec.size()); + for (uint64_t i = 0; i < returnedColVec.size(); i++) { RowAggFunctionType aggOp = functionIdMap(returnedColVec[i].second); @@ -1519,6 +1531,7 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate(JobInfo& jobInfo, vector> aggColVec; vector>& returnedColVec = jobInfo.returnedColVec; + aggColVec.reserve(returnedColVec.size()); for (uint64_t i = 0; i < returnedColVec.size(); i++) { @@ -1566,6 +1579,7 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate(JobInfo& jobInfo, vector width; + width.reserve(keysProj.size()); for (uint64_t i = 0; i < keysProj.size(); i++) { width.push_back(projRG.getColumnWidth(i)); @@ -1580,6 +1594,7 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate(JobInfo& jobInfo, vector projColPosMap; + widthProj.reserve(keysProj.size()); for (uint64_t i = 0; i < keysProj.size(); i++) { projColPosMap.insert(make_pair(keysProj[i], i)); @@ -1589,6 +1604,28 @@ void TupleAggregateStep::prep1PhaseDistinctAggregate(JobInfo& jobInfo, vector vector> aggColVec; set avgSet; vector>& returnedColVec = jobInfo.returnedColVec; + aggColVec.reserve(returnedColVec.size()); // For UDAF uint32_t projColsUDAFIdx = 0; uint32_t udafcParamIdx = 0; @@ -2977,6 +3015,7 @@ void TupleAggregateStep::prep2PhasesAggregate(JobInfo& jobInfo, vector // project only unique oids, but they may be repeated in aggregation // collect the projected column info, prepare for aggregation vector width; + width.reserve(keysProj.size()); map projColPosMap; for (uint64_t i = 0; i < keysProj.size(); i++) @@ -2988,6 +3027,18 @@ void TupleAggregateStep::prep2PhasesAggregate(JobInfo& jobInfo, vector // column index for PM aggregate rowgroup uint64_t colAggPm = 0; + // Reserve space for PM aggregate vectors + size_t reserveSize = returnedColVec.size() + jobInfo.groupByColVec.size(); + oidsAggPm.reserve(reserveSize); + keysAggPm.reserve(reserveSize); + scaleAggPm.reserve(reserveSize); + precisionAggPm.reserve(reserveSize); + typeAggPm.reserve(reserveSize); + csNumAggPm.reserve(reserveSize); + widthAggPm.reserve(reserveSize); + groupByPm.reserve(jobInfo.groupByColVec.size()); + functionVecPm.reserve(reserveSize); + // for groupby column for (uint64_t i = 0; i < jobInfo.groupByColVec.size(); i++) { @@ -3877,6 +3928,7 @@ void TupleAggregateStep::prep2PhasesDistinctAggregate(JobInfo& jobInfo, vector width; + width.reserve(keysProj.size()); map projColPosMap; for (uint64_t i = 0; i < keysProj.size(); i++) diff --git a/dbcon/joblist/windowfunctionstep.cpp b/dbcon/joblist/windowfunctionstep.cpp index 055ad29ad..e0f563afe 100644 --- a/dbcon/joblist/windowfunctionstep.cpp +++ b/dbcon/joblist/windowfunctionstep.cpp @@ -629,6 +629,7 @@ void WindowFunctionStep::initialize(const RowGroup& rg, JobInfo& jobInfo) vector fields; fields.push_back(ridx); // result const RetColsVector& parms = wc->functionParms(); + fields.reserve(1 + parms.size()); for (uint64_t i = 0; i < parms.size(); i++) // arguments { @@ -641,9 +642,13 @@ void WindowFunctionStep::initialize(const RowGroup& rg, JobInfo& jobInfo) // partition & order by const RetColsVector& partitions = wc->partitions(); + const RetColsVector& orders = wc->orderBy().fOrders; vector eqIdx; + eqIdx.reserve(partitions.size()); vector peerIdx; + peerIdx.reserve(orders.size()); vector sorts; + sorts.reserve(partitions.size() + orders.size()); for (uint64_t i = 0; i < partitions.size(); i++) { @@ -657,8 +662,6 @@ void WindowFunctionStep::initialize(const RowGroup& rg, JobInfo& jobInfo) sorts.push_back(IdbSortSpec(idx, partitions[i]->asc(), partitions[i]->nullsFirst())); } - const RetColsVector& orders = wc->orderBy().fOrders; - for (uint64_t i = 0; i < orders.size(); i++) { // skip constant column diff --git a/dbcon/mysql/ha_mcs_execplan.cpp b/dbcon/mysql/ha_mcs_execplan.cpp index 014b79a81..701aac3b1 100644 --- a/dbcon/mysql/ha_mcs_execplan.cpp +++ b/dbcon/mysql/ha_mcs_execplan.cpp @@ -6936,6 +6936,7 @@ int processSelect(SELECT_LEX& select_lex, gp_walk_info& gwi, SCSEP& csep, vector for (uint32_t i = 0; i < gwi.returnedCols.size(); i++) { vector coltypes; + coltypes.reserve(csep->unionVec().size()); for (uint32_t j = 0; j < csep->unionVec().size(); j++) { diff --git a/dbcon/mysql/ha_mcs_impl.cpp b/dbcon/mysql/ha_mcs_impl.cpp index e2b47e997..07f32fa90 100644 --- a/dbcon/mysql/ha_mcs_impl.cpp +++ b/dbcon/mysql/ha_mcs_impl.cpp @@ -3119,6 +3119,7 @@ void ha_mcs_impl_start_bulk_insert(ha_rows rows, TABLE* table, bool is_cache_ins //@bug 6122 Check how many columns have not null constraint. columnn with not null constraint will not // show up in header. unsigned int numberNotNull = 0; + ci->columnTypes.reserve(colrids.size()); for (unsigned int j = 0; j < colrids.size(); j++) { diff --git a/dbcon/mysql/ha_window_function.cpp b/dbcon/mysql/ha_window_function.cpp index 769781472..887ebbef3 100644 --- a/dbcon/mysql/ha_window_function.cpp +++ b/dbcon/mysql/ha_window_function.cpp @@ -327,6 +327,8 @@ ReturnedColumn* buildWindowFunctionColumn(Item* item, gp_walk_info& gwi, bool& n CalpontSystemCatalog::ColType ct; // For return type // arguments vector funcParms; + // Reserve space for arguments (may add more constants later in switch statement) + funcParms.reserve(item_sum->argument_count() + 3); for (uint32_t i = 0; i < item_sum->argument_count(); i++) { diff --git a/primitives/primproc/columncommand.cpp b/primitives/primproc/columncommand.cpp index a3bd8ba5b..bf2f9696e 100644 --- a/primitives/primproc/columncommand.cpp +++ b/primitives/primproc/columncommand.cpp @@ -954,6 +954,12 @@ void ColumnCommand::getLBIDList(uint32_t loopCount, vector* lbids) { int64_t firstLBID = lbid, lastLBID = firstLBID + (loopCount * colType.colWidth) - 1, i; + // Reserve space for all LBIDs we'll add + size_t lbidCount = (loopCount * colType.colWidth); + if (hasAuxCol_) + lbidCount += (loopCount * execplan::AUX_COL_WIDTH); + lbids->reserve(lbids->size() + lbidCount); + for (i = firstLBID; i <= lastLBID; i++) lbids->push_back(i); diff --git a/utils/batchloader/batchloader.cpp b/utils/batchloader/batchloader.cpp index a1e7697d7..0ea7b1697 100644 --- a/utils/batchloader/batchloader.cpp +++ b/utils/batchloader/batchloader.cpp @@ -461,6 +461,7 @@ void BatchLoader::buildBatchDistSeqVector(uint32_t StartPm) aPms = fPMs; else { + aPms.reserve(1 + fPMs.size()); // Reserve for StartPm + all potential PMs aPms.push_back(StartPm); uint32_t aLast = fPMs.back(); uint32_t aFirst = fPMs.front(); diff --git a/utils/joiner/joinpartition.cpp b/utils/joiner/joinpartition.cpp index d07a380cf..f4cbb74f2 100644 --- a/utils/joiner/joinpartition.cpp +++ b/utils/joiner/joinpartition.cpp @@ -327,6 +327,8 @@ bool JoinPartition::canConvertToSplitMode() RGData rgData; uint64_t totalRowCount = 0; std::unordered_map rowDist; + // Reserve space for hash distribution (one entry per bucket) + rowDist.reserve(bucketCount); nextSmallOffset = 0; while (1) diff --git a/utils/joiner/tuplejoiner.cpp b/utils/joiner/tuplejoiner.cpp index 7d3b59114..23e558338 100644 --- a/utils/joiner/tuplejoiner.cpp +++ b/utils/joiner/tuplejoiner.cpp @@ -769,7 +769,8 @@ void TupleJoiner::doneInserting() smallRow.setPointer(sthit->second); ++sthit; } - + // Reserve space up to uniqueLimit+1 to avoid reallocations during unique value tracking + uniquer.reserve(std::min(uniqueLimit + 1, rowCount)); if (isLongDouble(smallSideColType)) { double dval = (double)roundl(smallRow.getLongDoubleField(smallSideColIdx)); diff --git a/utils/rowgroup/rowgroup.cpp b/utils/rowgroup/rowgroup.cpp index cfc2aa770..92271f798 100644 --- a/utils/rowgroup/rowgroup.cpp +++ b/utils/rowgroup/rowgroup.cpp @@ -1599,6 +1599,16 @@ RowGroup& RowGroup::operator+=(const RowGroup& rhs) forceInline.swap(tmp); columnCount += rhs.columnCount; + // Reserve space for all vectors that will be appended + oids.reserve(oids.size() + rhs.oids.size()); + keys.reserve(keys.size() + rhs.keys.size()); + types.reserve(types.size() + rhs.types.size()); + charsetNumbers.reserve(charsetNumbers.size() + rhs.charsetNumbers.size()); + charsets.reserve(charsets.size() + rhs.charsets.size()); + scale.reserve(scale.size() + rhs.scale.size()); + precision.reserve(precision.size() + rhs.precision.size()); + colWidths.reserve(colWidths.size() + rhs.colWidths.size()); + oids.insert(oids.end(), rhs.oids.begin(), rhs.oids.end()); keys.insert(keys.end(), rhs.keys.begin(), rhs.keys.end()); types.insert(types.end(), rhs.types.begin(), rhs.types.end()); @@ -1610,6 +1620,12 @@ RowGroup& RowGroup::operator+=(const RowGroup& rhs) // +4 +4 +8 +2 +4 +8 // (2, 6, 10, 18) + (2, 4, 8, 16) = (2, 6, 10, 18, 20, 24, 32) + // Reserve space for additional offsets from rhs (starting from index 1) + if (rhs.stOffsets.size() > 1) + { + stOffsets.reserve(stOffsets.size() + rhs.stOffsets.size() - 1); + oldOffsets.reserve(oldOffsets.size() + rhs.oldOffsets.size() - 1); + } for (i = 1; i < rhs.stOffsets.size(); i++) { stOffsets.push_back(stOffsets.back() + rhs.stOffsets[i] - rhs.stOffsets[i - 1]); diff --git a/utils/rowgroup/rowstorage.cpp b/utils/rowgroup/rowstorage.cpp index 8ab629873..8435410ca 100644 --- a/utils/rowgroup/rowstorage.cpp +++ b/utils/rowgroup/rowstorage.cpp @@ -1234,6 +1234,8 @@ class RowGroupStorage void getTmpFilePrefixes(std::vector& prefixes) const { char buf[PATH_MAX]; + // Reserve space for 2 prefixes + prefixes.reserve(prefixes.size() + 2); snprintf(buf, sizeof(buf), "Agg-p%u-t%p-rg", getpid(), fUniqId); prefixes.emplace_back(buf); diff --git a/versioning/BRM/extentmap.cpp b/versioning/BRM/extentmap.cpp index 1b3bd4198..2357db53c 100644 --- a/versioning/BRM/extentmap.cpp +++ b/versioning/BRM/extentmap.cpp @@ -1412,6 +1412,7 @@ int ExtentMap::getMaxMin(const LBID_t lbid, T& max, T& min, int32_t& seqNum) std::vector ExtentMap::getEmIdentsByLbids(const bi::vector& lbids) { std::vector emEntries; + emEntries.reserve(lbids.size()); for (auto lbid : lbids) { auto emIt = findByLBID(lbid); @@ -1427,6 +1428,7 @@ std::vector ExtentMap::getEmIteratorsByLbids(const bi { // ExtentMapRBTree::iterator std::vector emEntries; + emEntries.reserve(lbids.size()); for (auto lbid : lbids) { auto emIt = findByLBID(lbid); diff --git a/writeengine/bulk/we_bulkload.cpp b/writeengine/bulk/we_bulkload.cpp index 9e2b22099..1a636dcfe 100644 --- a/writeengine/bulk/we_bulkload.cpp +++ b/writeengine/bulk/we_bulkload.cpp @@ -329,7 +329,7 @@ int BulkLoad::loadJobInfo(const string& fullName, bool bUseTempJobFile, int argc fLog.logMsg(oss.str(), rc, MSGLVL_ERROR); return rc; } - catch(std::exception& ex) + catch (std::exception& ex) { rc = ERR_UNKNOWN; std::ostringstream oss; @@ -338,7 +338,7 @@ int BulkLoad::loadJobInfo(const string& fullName, bool bUseTempJobFile, int argc fLog.logMsg(oss.str(), rc, MSGLVL_ERROR); return rc; } - catch(...) + catch (...) { rc = ERR_UNKNOWN; std::ostringstream oss; @@ -352,10 +352,10 @@ int BulkLoad::loadJobInfo(const string& fullName, bool bUseTempJobFile, int argc // tableAUXColOid = 0 if (tableAUXColOid > 3000) { - JobColumn curColumn("aux", tableAUXColOid, execplan::AUX_COL_DATATYPE_STRING, - execplan::AUX_COL_WIDTH, execplan::AUX_COL_WIDTH, - execplan::AUX_COL_COMPRESSION_TYPE, execplan::AUX_COL_COMPRESSION_TYPE, - execplan::AUX_COL_MINVALUE, execplan::AUX_COL_MAXVALUE, true, 1); + JobColumn curColumn("aux", tableAUXColOid, execplan::AUX_COL_DATATYPE_STRING, execplan::AUX_COL_WIDTH, + execplan::AUX_COL_WIDTH, execplan::AUX_COL_COMPRESSION_TYPE, + execplan::AUX_COL_COMPRESSION_TYPE, execplan::AUX_COL_MINVALUE, + execplan::AUX_COL_MAXVALUE, true, 1); curColumn.fFldColRelation = BULK_FLDCOL_COLUMN_DEFAULT; curJob.jobTableList[i].colList.push_back(curColumn); JobFieldRef fieldRef(BULK_FLDCOL_COLUMN_DEFAULT, curJob.jobTableList[i].colList.size() - 1); @@ -711,7 +711,8 @@ int BulkLoad::preProcess(Job& job, int tableNo, std::shared_ptr& tabl tableInfo.get()); // tableInfo->rbMetaWriter()); else - info = new ColumnInfo(&fLog, i, job.jobTableList[tableNo].colList[i], pDBRootExtentTracker, tableInfo.get()); + info = new ColumnInfo(&fLog, i, job.jobTableList[tableNo].colList[i], pDBRootExtentTracker, + tableInfo.get()); if (pwd) info->setUIDGID(pwd->pw_uid, pwd->pw_gid); @@ -877,7 +878,8 @@ int BulkLoad::preProcessAutoInc(const std::string& fullTableName, ColumnInfo* co // NO_ERROR if success // other if fail //------------------------------------------------------------------------------ -int BulkLoad::preProcessHwmLbid(const ColumnInfo* info, int /*minWidth*/, uint32_t partition, uint16_t segment, +int BulkLoad::preProcessHwmLbid(const ColumnInfo* info, int /*minWidth*/, uint32_t partition, + uint16_t segment, HWM& hwm, // input/output BRM::LBID_t& lbid, // output bool& bSkippedToNewExtent) // output @@ -1020,11 +1022,13 @@ int BulkLoad::processJob() // Validate the existence of the import data files //-------------------------------------------------------------------------- std::vector> tables; + tables.reserve(curJob.jobTableList.size()); for (i = 0; i < curJob.jobTableList.size(); i++) { - std::shared_ptr tableInfo(new TableInfo(&fLog, fTxnID, fProcessName, curJob.jobTableList[i].mapOid, - curJob.jobTableList[i].tblName, fKeepRbMetaFiles)); + std::shared_ptr tableInfo(new TableInfo(&fLog, fTxnID, fProcessName, + curJob.jobTableList[i].mapOid, + curJob.jobTableList[i].tblName, fKeepRbMetaFiles)); if ((fBulkMode == BULK_MODE_REMOTE_SINGLE_SRC) || (fBulkMode == BULK_MODE_REMOTE_MULTIPLE_SRC)) tableInfo->setBulkLoadMode(fBulkMode, fBRMRptFileName); @@ -1365,7 +1369,6 @@ int BulkLoad::buildImportDataFileList(const std::string& location, const std::st fullPath += token; } - // If running mode2, then support a filename with wildcards if (fBulkMode == BULK_MODE_REMOTE_MULTIPLE_SRC) { diff --git a/writeengine/bulk/we_colbufcompressed.cpp b/writeengine/bulk/we_colbufcompressed.cpp index 9678501c2..9a19bdcc5 100644 --- a/writeengine/bulk/we_colbufcompressed.cpp +++ b/writeengine/bulk/we_colbufcompressed.cpp @@ -572,6 +572,7 @@ int ColumnBufferCompressed::saveCompressionHeaders() compress::CompressInterface::setLBIDByIndex(hdrBuf, fColInfo->getLastUpdatedLBID(), 0); std::vector ptrs; + ptrs.reserve(fChunkPtrs.size() + 1); // +1 for the final ptr after the loop for (unsigned i = 0; i < fChunkPtrs.size(); i++) { diff --git a/writeengine/bulk/we_extentstripealloc.cpp b/writeengine/bulk/we_extentstripealloc.cpp index 98463e1b3..007c17f17 100644 --- a/writeengine/bulk/we_extentstripealloc.cpp +++ b/writeengine/bulk/we_extentstripealloc.cpp @@ -155,6 +155,7 @@ int ExtentStripeAlloc::allocateExtent(OID oid, uint16_t dbRoot, fLog->logMsg(oss1.str(), MSGLVL_INFO2); std::vector cols; + cols.reserve(fColOIDs.size()); std::vector extents; for (unsigned int j = 0; j < fColOIDs.size(); ++j) diff --git a/writeengine/server/we_ddlcommandproc.cpp b/writeengine/server/we_ddlcommandproc.cpp index 350647ab1..a78474254 100644 --- a/writeengine/server/we_ddlcommandproc.cpp +++ b/writeengine/server/we_ddlcommandproc.cpp @@ -363,6 +363,7 @@ uint8_t WE_DDLCommandProc::writeCreateSyscolumn(ByteStream& bs, std::string& err // deserialize column Oid and dictionary oid vector coloids; + coloids.reserve(columnSize); vector dictoids; for (i = 0; i < columnSize; ++i) @@ -372,6 +373,7 @@ uint8_t WE_DDLCommandProc::writeCreateSyscolumn(ByteStream& bs, std::string& err } bs >> dictSize; + dictoids.reserve(dictSize); for (i = 0; i < dictSize; ++i) { @@ -2089,6 +2091,7 @@ uint8_t WE_DDLCommandProc::updateSyscolumnAuto(ByteStream& bs, std::string& err) dctnryStructList.push_back(dctnryStruct); cscColTypeList.push_back(column.colType); + aColList.reserve(roList.size()); for (unsigned int i = 0; i < roList.size(); i++) { aColList.push_back(colTuple); @@ -2276,6 +2279,7 @@ uint8_t WE_DDLCommandProc::updateSyscolumnNextvalCol(ByteStream& bs, std::string dctnryStructList.push_back(dctnryStruct); cscColTypeList.push_back(column.colType); + aColList.reserve(roList.size()); for (unsigned int i = 0; i < roList.size(); i++) { aColList.push_back(colTuple); @@ -2449,6 +2453,7 @@ uint8_t WE_DDLCommandProc::updateSystableEntryForSysColumn(int32_t /*sessionID*/ dctnryStructList.push_back(dctnryStruct); cscColTypeList.push_back(column.colType); + aColList.reserve(roList.size()); for (unsigned int i = 0; i < roList.size(); i++) { aColList.push_back(colTuple); diff --git a/writeengine/server/we_dmlcommandproc.cpp b/writeengine/server/we_dmlcommandproc.cpp index fff5ece08..69d6e4492 100644 --- a/writeengine/server/we_dmlcommandproc.cpp +++ b/writeengine/server/we_dmlcommandproc.cpp @@ -502,6 +502,7 @@ uint8_t WE_DMLCommandProc::processSingleInsert(messageqcpp::ByteStream& bs, std: // First gather HWM BRM information for all columns std::vector colWidths; + colWidths.reserve(ridList.size()); for (unsigned i = 0; i < ridList.size(); i++) { @@ -609,6 +610,7 @@ uint8_t WE_DMLCommandProc::processSingleInsert(messageqcpp::ByteStream& bs, std: std::map oids; std::vector oidsToFlush; + oidsToFlush.reserve(colStructs.size() + dctnryStructList.size()); for (unsigned i = 0; i < colStructs.size(); i++) { @@ -950,6 +952,7 @@ uint8_t WE_DMLCommandProc::processBatchInsert(messageqcpp::ByteStream& bs, std:: // First gather HWM BRM information for all columns std::vector colWidths; + colWidths.reserve(ridList.size() + 1); // +1 for potential AUX column for (unsigned i = 0; i < ridList.size(); i++) { rc = BRMWrapper::getInstance()->getDbRootHWMInfo(ridList[i].objnum, dbRootHWMInfoColVec[i]); diff --git a/writeengine/wrapper/writeengine.cpp b/writeengine/wrapper/writeengine.cpp index 41524aa0b..3b8b553fe 100644 --- a/writeengine/wrapper/writeengine.cpp +++ b/writeengine/wrapper/writeengine.cpp @@ -1392,6 +1392,7 @@ int WriteEngineWrapper::insertColumnRecs( if (bFirstExtentOnThisPM) { std::vector cols; + cols.reserve(colStructList.size()); BRM::CreateStripeColumnExtentsArgIn createStripeColumnExtentsArgIn; for (i = 0; i < colStructList.size(); i++) @@ -2202,6 +2203,7 @@ int WriteEngineWrapper::insertColumnRecsBinary( { // cout << "bFirstExtentOnThisPM is " << bFirstExtentOnThisPM << endl; std::vector cols; + cols.reserve(colStructList.size()); BRM::CreateStripeColumnExtentsArgIn createStripeColumnExtentsArgIn; for (i = 0; i < colStructList.size(); i++) diff --git a/writeengine/xml/we_xmljob.cpp b/writeengine/xml/we_xmljob.cpp index fd7bd85d6..5105a8707 100644 --- a/writeengine/xml/we_xmljob.cpp +++ b/writeengine/xml/we_xmljob.cpp @@ -757,6 +757,12 @@ void XMLJob::postProcessTableNode() bValidateNoDefColWithoutDefValue = true; int tableNo = fJob.jobTableList.size() - 1; + // Reserve space for default columns + fJob.jobTableList[tableNo].colList.reserve(fJob.jobTableList[tableNo].colList.size() + + fDefaultColumns.size()); + fJob.jobTableList[tableNo].fFldRefs.reserve(fJob.jobTableList[tableNo].fFldRefs.size() + + fDefaultColumns.size()); + for (unsigned k = 0; k < fDefaultColumns.size(); k++) { // Add to list of db columns to be loaded