Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
// -----------------------------------------------------------------------
// 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);
    }
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
// -----------------------------------------------------------------------
// 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.
        }
    }
}
Exemplo n.º 5
0
// Here is how we detect that:
// 1. indexColumn_.entries() == 1. (There can only be one IDENTITY column.)
// 2. Is this indexColumn_ an IDENTITY column? Look up the 
//    IDENTITY property in the BaseTable's TableDesc by using 
//    getPosition().  
void IndexDesc::markIdentityColumnUniqueIndex(TableDesc *tdesc)
{

  if(indexKey_.entries() != 1) 
    {
      // there can be only one IDENTITY col. id any
      return;
    }
  
  // Is this indexKey_ column an IDENTITY column? 
  
  CollIndex identityColPosition = indexKey_[0].getNAColumn()->getPosition();  
  ValueId identityValueId = tdesc->getColumnList()[identityColPosition];
  if (identityValueId.getNAColumn()->isIdentityColumn())
    identityColumnUniqueIndexFlag_ = TRUE;
 
  return;
}
Exemplo n.º 6
0
// 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;
}
Exemplo n.º 7
0
// ------------------------------------------------------------------------------
// create my colStats based on my child's output, by converting the columns to 
// that of mine
// ------------------------------------------------------------------------------
void EstLogProp::mapOutputsForUpdate(const GenericUpdate & updateExpr, 
				     const ValueIdMap & updateSelectValueIdMap)
{

  TableDesc * updateTable = updateExpr.getTableDesc();

  for ( CollIndex i = 0; i < colStats().entries(); i++ )
  {
    ColStatDescSharedPtr colStatPtr = (colStats())[i];     
    const ValueId columnId = colStatPtr->getVEGColumn();

    ValueId updateColVEGOutputId;
    updateSelectValueIdMap.mapValueIdUp(updateColVEGOutputId, columnId);
    ValueId updateBaseColumnId;

    if (updateColVEGOutputId != columnId)
    {
      updateBaseColumnId = updateColVEGOutputId;
     
      ValueIdSet baseColumns;
      updateColVEGOutputId.getItemExpr()->findAll( ITM_BASECOLUMN, baseColumns, TRUE, TRUE );

      // from all the columns extracted, get the one for Insert table
      TableDesc * thisTable = NULL;
      for (ValueId column = baseColumns.init(); baseColumns.next(column);
	  baseColumns.advance(column) )
      {
	ItemExpr * columnExpr = column.getItemExpr();
	thisTable = ((BaseColumn *)columnExpr)->getTableDesc();
	if (thisTable == updateTable)
	{
	  // set my column as the base column
	  updateBaseColumnId = column;
	  break;
	}
       }
       
       ColStatsSharedPtr inColStats = colStatPtr->getColStats();
       ColStatsSharedPtr colStatsForUpdate(new (STMTHEAP) ColStats (*inColStats,STMTHEAP));

       colStatsForUpdate->setStatColumn(updateBaseColumnId.getNAColumn());
       // use this ColStat to generate new ColStat corresponding to the char output
       // of the Update expression

       ColStatDescSharedPtr colStatDescForUpdate(new (STMTHEAP) ColStatDesc(colStatsForUpdate, 
					    updateBaseColumnId,  // ValueId of the column that will be used 
							 // as a column name, VEG and mergeStats
					    STMTHEAP), STMTHEAP);
       colStatDescForUpdate->VEGColumn() = updateColVEGOutputId;
       colStatDescForUpdate->mergeState().clear() ;
       colStatDescForUpdate->mergeState().insert(updateBaseColumnId);

       // Remove the old colStat and insert this colStat into the result colStatDescList
       colStats().removeAt( i );

       colStats().insertDeepCopyAt(i, colStatDescForUpdate, // colStats to be copied
				     1,			   // scale
				     FALSE);

    }
  }
}