src/backend/storage/data_table.cpp
/**
 * @brief Insert a tuple into all indexes. If index is primary/unique,
 * check visibility of existing
 * index entries.
 * @warning This still doesn't guarantee serializability.
 *
 * @returns True on success, false if a visible entry exists (in case of
 *primary/unique).
 */
@brief Insert a tuple into all indexes. If index is primary/unique,
check visibility of existing
index entries.
@warning This still doesn't guarantee serializability.

@returns True on success, false if a visible entry exists (in case of
primary/unique).
@brief Insert a tuple into all indexes . If index is primary / unique check visibility of existing index entries . @warning This still doesn ' t guarantee serializability . @returns True on success false if a visible entry exists ( in case of primary / unique ) .
bool DataTable::InsertInIndexes(const storage::Tuple *tuple,
                                ItemPointer location) {
  int index_count = GetIndexCount();
  auto &transaction_manager =
      concurrency::TransactionManagerFactory::GetInstance();
  std::function<bool(const ItemPointer &)> fn =
      std::bind(&concurrency::TransactionManager::IsOccupied,
                &transaction_manager, std::placeholders::_1);
  for (int index_itr = index_count - 1; index_itr >= 0; --index_itr) {
    auto index = GetIndex(index_itr);
    auto index_schema = index->GetKeySchema();
    auto indexed_columns = index_schema->GetIndexedColumns();
    std::unique_ptr<storage::Tuple> key(new storage::Tuple(index_schema, true));
    key->SetFromTuple(tuple, indexed_columns, index->GetPool());
    switch (index->GetIndexType()) {
      case INDEX_CONSTRAINT_TYPE_PRIMARY_KEY:
      case INDEX_CONSTRAINT_TYPE_UNIQUE: {
        if (index->CondInsertEntry(key.get(), location, fn) == false) {
          return false;
        }
      } break;
      case INDEX_CONSTRAINT_TYPE_DEFAULT:
      default:
        index->InsertEntry(key.get(), location);
        break;
    }
    LOG_TRACE("Index constraint check on %s passed.", index->GetName().c_str());
  }
  return true;
}
bool DataTable :: InsertInIndexes ( const storage :: Tuple * tuple , ItemPointer location ) { int index_count = GetIndexCount ( ) ; auto & transaction_manager = concurrency :: TransactionManagerFactory :: GetInstance ( ) ; std :: function < bool ( const ItemPointer & ) > fn = std :: bind ( & concurrency :: TransactionManager :: IsOccupied , & transaction_manager , std :: placeholders :: _1 ) ; for ( int index_itr = index_count - 1 ; index_itr >= 0 ; -- index_itr ) { auto index = GetIndex ( index_itr ) ; auto index_schema = index -> GetKeySchema ( ) ; auto indexed_columns = index_schema -> GetIndexedColumns ( ) ; std :: unique_ptr < storage :: Tuple > key ( new storage :: Tuple ( index_schema , true ) ) ; key -> SetFromTuple ( tuple , indexed_columns , index -> GetPool ( ) ) ; switch ( index -> GetIndexType ( ) ) { case INDEX_CONSTRAINT_TYPE_PRIMARY_KEY : case INDEX_CONSTRAINT_TYPE_UNIQUE : { if ( index -> CondInsertEntry ( key . get ( ) , location , fn ) == false ) { return false ; } } break ; case INDEX_CONSTRAINT_TYPE_DEFAULT : default : index -> InsertEntry ( key . get ( ) , location ) ; break ; } LOG_TRACE ( " " , index -> GetName ( ) . c_str ( ) ) ; } return true ; }
@brief Insert a tuple into all indexes.
@brief Insert a tuple into all indexes .
// (A) Check existence for primary/unique indexes // FIXME Since this is NOT protected by a lock, concurrent insert may happen. // TODO: get unique tuple from primary index. // if in this index there has been a visible or uncommitted // <key, location> pair, this constraint is violated