Beispiel #1
0
ItemPointer DataTable::InsertTuple(const storage::Tuple *tuple) {
  // First, do integrity checks and claim a slot
  ItemPointer location = GetEmptyTupleSlot(tuple);
  if (location.block == INVALID_OID) {
    LOG_TRACE("Failed to get tuple slot.");
    return INVALID_ITEMPOINTER;
  }

  LOG_TRACE("Location: %u, %u", location.block, location.offset);

  // Index checks and updates
  if (InsertInIndexes(tuple, location) == false) {
    LOG_TRACE("Index constraint violated");
    return INVALID_ITEMPOINTER;
  }

  // ForeignKey checks
  if (CheckForeignKeyConstraints(tuple) == false) {
    LOG_TRACE("ForeignKey constraint violated");
    return INVALID_ITEMPOINTER;
  }

  // Increase the table's number of tuples by 1
  IncreaseNumberOfTuplesBy(1);
  // Increase the indexes' number of tuples by 1 as well
  for (auto index : indexes_) index->IncreaseNumberOfTuplesBy(1);

  return location;
}
Beispiel #2
0
ItemPointer DataTable::InsertVersion(const storage::Tuple *tuple) {
  // First, do integrity checks and claim a slot
  ItemPointer location = GetEmptyTupleSlot(tuple, true);
  if (location.block == INVALID_OID) {
    LOG_TRACE("Failed to get tuple slot.");
    return INVALID_ITEMPOINTER;
  }

  // Index checks and updates
  if (InsertInSecondaryIndexes(tuple, location) == false) {
    LOG_TRACE("Index constraint violated");
    return INVALID_ITEMPOINTER;
  }

  // ForeignKey checks
  if (CheckForeignKeyConstraints(tuple) == false) {
    LOG_TRACE("ForeignKey constraint violated");
    return INVALID_ITEMPOINTER;
  }

  LOG_TRACE("Location: %u, %u", location.block, location.offset);

  IncreaseNumberOfTuplesBy(1);
  return location;
}
Beispiel #3
0
ItemPointer DataTable::AcquireVersion() {
  // First, claim a slot
  ItemPointer location = GetEmptyTupleSlot(nullptr);
  if (location.block == INVALID_OID) {
    LOG_TRACE("Failed to get tuple slot.");
    return INVALID_ITEMPOINTER;
  }

  LOG_TRACE("Location: %u, %u", location.block, location.offset);

  IncreaseTupleCount(1);
  return location;
}
Beispiel #4
0
// insert tuple into a table that is without index.
ItemPointer DataTable::InsertTuple(const storage::Tuple *tuple) {
  ItemPointer location = GetEmptyTupleSlot(tuple);
  if (location.block == INVALID_OID) {
    LOG_TRACE("Failed to get tuple slot.");
    return INVALID_ITEMPOINTER;
  }

  LOG_TRACE("Location: %u, %u", location.block, location.offset);

  UNUSED_ATTRIBUTE auto index_count = GetIndexCount();
  PL_ASSERT(index_count == 0);
  // Increase the table's number of tuples by 1
  IncreaseTupleCount(1);
  return location;
}
Beispiel #5
0
ItemPointer DataTable::InsertTuple(const storage::Tuple *tuple,
                                   concurrency::Transaction *transaction,
                                   ItemPointer **index_entry_ptr) {
  // the upper layer may not pass a index_entry_ptr (default value: nullptr)
  // into the function.
  // in this case, we have to create a temp_ptr to hold the content.
  ItemPointer *temp_ptr = nullptr;

  if (index_entry_ptr == nullptr) {
    index_entry_ptr = &temp_ptr;
  }

  ItemPointer location = GetEmptyTupleSlot(tuple);
  if (location.block == INVALID_OID) {
    LOG_TRACE("Failed to get tuple slot.");
    return INVALID_ITEMPOINTER;
  }

  LOG_TRACE("Location: %u, %u", location.block, location.offset);

  auto index_count = GetIndexCount();
  if (index_count == 0) {
    // Increase the table's number of tuples by 1
    IncreaseTupleCount(1);
    return location;
  }
  // Index checks and updates
  if (InsertInIndexes(tuple, location, transaction, index_entry_ptr) == false) {
    LOG_TRACE("Index constraint violated");
    return INVALID_ITEMPOINTER;
  }

  // ForeignKey checks
  if (CheckForeignKeyConstraints(tuple) == false) {
    LOG_TRACE("ForeignKey constraint violated");
    return INVALID_ITEMPOINTER;
  }

  PL_ASSERT((*index_entry_ptr)->block == location.block &&
            (*index_entry_ptr)->offset == location.offset);

  // Increase the table's number of tuples by 1
  IncreaseTupleCount(1);

  return location;
}