NABoolean TableDesc::isIdentityColumnGeneratedAlways(NAString * value) const { // Determine if an IDENTITY column exists and // has the default class of GENERATED ALWAYS AS IDENTITY. // Do not return TRUE, if the table type is an INDEX_TABLE. NABoolean result = FALSE; for (CollIndex j = 0; j < colList_.entries(); j++) { ValueId valId = colList_[j]; NAColumn *column = valId.getNAColumn(); if(column->isIdentityColumnAlways()) { if (getNATable()->getObjectType() != COM_INDEX_OBJECT) { if (value != NULL) *value = column->getColName(); result = TRUE; } } } return result; }
// is this BaseColumn a primary or partitioning key and is val a single // value or a constant that can be safely coerced to BaseColumn's type? NABoolean BaseColumn::isKeyColumnValue(ItemExpr& val) const { NAColumn *baseCol = getNAColumn(); return (baseCol != NULL && (baseCol->isPrimaryKey() || baseCol->isPartitioningKey()) && canSafelyCoerce(val)); }
//gets the NAColumn that has the same position NAColumn * NAColumnArray::getColumnByPos(Lng32 position) const { for (CollIndex i = 0; i < entries(); i++) { NAColumn *column = (*this)[i]; if (column->getPosition() == position) return column; } return NULL; }
NAColumn *NAColumnArray::getColumn(const char *colName) const { for (CollIndex i = 0; i < entries(); i++) { NAColumn *column = (*this)[i]; if (column->getColName() == colName) return column; } return NULL; }
// ----------------------------------------------------------------------- // TableDesc::getSystemColumnList() // ----------------------------------------------------------------------- void TableDesc::getSystemColumnList(ValueIdList &columnList) const { for (CollIndex i = 0; i < colList_.entries(); i++) { ValueId valId = colList_[i]; NAColumn *column = valId.getNAColumn(); if (column->isSystemColumn()) columnList.insert(valId); } }
// LCOV_EXCL_START :cnu // removes the column that has the same position void NAColumnArray::removeByPosition(Lng32 position) { for(CollIndex i=0;i < entries();i++) { NAColumn * column = (*this)[i]; if(column->getPosition() == position) { this->removeAt(i); break; } } }
NABoolean TableDesc::hasIdentityColumnInClusteringKey() const { ValueIdSet pKeyColumns = clusteringIndex_->getIndexKey(); NAColumn * column = NULL; for(ValueId id = pKeyColumns.init(); pKeyColumns.next(id); pKeyColumns.advance(id)) { column = id.getNAColumn(); if (column && column->isIdentityColumn()) return TRUE; } return FALSE; }
// ----------------------------------------------------------------------- // TableDesc::getIdentityColumn() // ----------------------------------------------------------------------- void TableDesc::getIdentityColumn(ValueIdList &columnList) const { for (CollIndex i = 0; i < colList_.entries(); i++) { ValueId valId = colList_[i]; NAColumn *column = valId.getNAColumn(); if (column->isIdentityColumn()) { columnList.insert(valId); break; // Break when you find the first, // as there can only be one Identity column per table. } } }
// is val a constant that can be safely coerced to BaseColumn's type? NABoolean BaseColumn::canSafelyCoerce(ItemExpr& val) const { NAColumn *baseCol = getNAColumn(); OperatorTypeEnum valTyp = val.getOperatorType(); return (baseCol != NULL && ((valTyp == ITM_CONSTANT && ((ConstValue*)&val)->canBeSafelyCoercedTo(*baseCol->getType())) // we don't need to check the types of param & hostvar here because we // are called after ItemExpr::bindNode has successfully type-checked // the current search predicate that is being tested for cacheability || valTyp == ITM_HOSTVAR || valTyp == ITM_DYN_PARAM || valTyp == ITM_CACHE_PARAM )); }
ULng32 NAColumnArray::getMaxTrafHbaseColQualifier() const { NAColumn *column; char * colQualPtr; Lng32 colQualLen; Int64 colQVal; ULng32 maxVal = 0; for (CollIndex i = 0; i < entries(); i++) { column = (*this)[i]; colQualPtr = (char*)column->getHbaseColQual().data(); colQualLen = column->getHbaseColQual().length(); colQVal = str_atoi(colQualPtr, colQualLen); if (colQVal > maxVal) maxVal = colQVal ; } return maxVal; }
// this method sets the primary key columns. It goes through all the columns // of the table, and collects the columns which are marked as primary keys void TableDesc::setPrimaryKeyColumns() { ValueIdSet primaryColumns; for ( CollIndex j = 0 ; j < colList_.entries() ; j++ ) { ValueId valId = colList_[j]; NAColumn *column = valId.getNAColumn(); if ( column->isPrimaryKey() ) { primaryColumns.insert(valId) ; // mark column as referenced for histogram, as we may need its histogram // during plan generation if ((column->isUserColumn() || column->isSaltColumn() ) && (column->getNATable()->getSpecialType() == ExtendedQualName::NORMAL_TABLE) ) column->setReferencedForMultiIntHist(); } } primaryKeyColumns_ = primaryColumns; }
NABoolean NAColumn::operator==(const NAColumn& other) const { return ((getColName() == other.getColName()) && (*getType() == *other.getType())); }
// --------------------------------------------------------------------- // Utility Routine: pickOutputs // // From the given ColStatDescList, populate columnStats_ with column // descriptors that are useful based on the characteristic outputs for // the group. // // Always include in the output the current histograms of the input data, // and, if the histogram is contained in the required output list, then // this is a useful histogram and will also be output. // // --------------------------------------------------------------------- void EstLogProp::pickOutputs( ColStatDescList & columnStats, const EstLogPropSharedPtr& inputEstLogProp, const ValueIdSet specifiedOutputs, const ValueIdSet predSet) { const ColStatDescList & outerColStatsList = inputEstLogProp->getColStats(); ValueIdSet colsRequiringHistograms = specifiedOutputs; // (i) see if the selection predicates contain any constant value or a // constant expression // (ii) check if there are any columns of this table being joined to some other // columns, which do not appear as characteristics outputs. There should be // histograms available for these columns, as these might be needed later. // This problem was seen for temporary tables created as normal_tables by the // triggers. colsRequiringHistograms.addSet(predSet.getColumnsForHistogram()); colStats().setMCSkewedValueLists(columnStats.getMCSkewedValueLists()) ; NABoolean colStatDescAdded = FALSE; for (CollIndex i=0; i < columnStats.entries(); i++) { // we probably don't need 'em all, but this is the easiest way to // grab all of the multi-column uec information we'll need later colStats().insertIntoUecList (columnStats.getUecList()) ; colStats().setScanRowCountWithoutHint(columnStats.getScanRowCountWithoutHint()); NABoolean found = FALSE; // Note: The following inserts into a ColStatDescList should not // have to be deep copies. From this point on, ColStatDescs that // describe the output of the calling operator are read-only. ColStatDescSharedPtr colStatDesc = columnStats[i]; // the value-id we're looking for const ValueId columnId = colStatDesc->getVEGColumn() ; for (CollIndex j=0 ; j < outerColStatsList.entries() ; j++) { if (columnId == outerColStatsList[j]->getVEGColumn() OR (CmpCommon::context()->showQueryStats())) { colStats().insert(colStatDesc) ; found = TRUE; if(!colStatDescAdded) colStatDescAdded = TRUE; break ; // jump to next ColStatDesc } } // OK, the valueid doesn't match directly -- but there are still a // couple of things to check in order to verify whether or not we're // interested in keeping the i'th ColStatDesc ... ValueId throwaway ; // used by the second clause below if ( NOT found AND (columnId != NULL_VALUE_ID) AND (colsRequiringHistograms.contains (columnId) OR colsRequiringHistograms.referencesTheGivenValue (columnId, throwaway) OR columnId.isInvolvedInJoinAndConst() OR CmpCommon::context()->showQueryStats() ) ) { colStats().insert(colStatDesc); found = TRUE; if(!colStatDescAdded) colStatDescAdded = TRUE; } if (CURRSTMT_OPTDEFAULTS->incorporateSkewInCosting()) { // if the column is referenced for histogram, but is // not needed beyond this time , then we shall save its // max freq, which might be used later in costing if this // column is a part of the partitioning key ColStatsSharedPtr stat = colStatDesc->getColStats(); if (!(stat->isVirtualColForHist() ) && NOT found && !(stat->isOrigFakeHist() ) ) { const ValueId col = colStatDesc->getColumn(); ColAnalysis * colAnalysis = col.colAnalysis(); if (colAnalysis) { NAColumn * column = stat->getStatColumns()[0]; if (column->isReferencedForHistogram()) { CostScalar maxFreq = columnStats.getMaxFreq(columnId); colAnalysis->setMaxFreq(maxFreq); colAnalysis->setFinalUec(stat->getTotalUec()); colAnalysis->setFinalRC(stat->getRowcount()); } } } } } // for columnStats.entries() if(!colStatDescAdded && columnStats.entries() > 0) colStats().insert(columnStats[0]) ; } // pickOutputs