Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move scans of tableID into node/relIDs out of Column #1550

Merged
merged 1 commit into from
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 15 additions & 48 deletions src/include/storage/storage_structure/column.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,17 @@ namespace storage {

using scan_data_func_t = std::function<void(transaction::Transaction* transaction, uint8_t* frame,
PageElementCursor& pageCursor, common::ValueVector* resultVector, uint32_t posInVector,
uint32_t numElementsPerPage, uint32_t numValuesToRead, common::table_id_t commonTableID,
DiskOverflowFile* diskOverflowFile)>;
uint32_t numElementsPerPage, uint32_t numValuesToRead, DiskOverflowFile* diskOverflowFile)>;
using lookup_data_func_t = std::function<void(transaction::Transaction* transaction, uint8_t* frame,
PageElementCursor& pageCursor, common::ValueVector* resultVector, uint32_t posInVector,
uint32_t numElementsPerPage, common::table_id_t commonTableID,
DiskOverflowFile* diskOverflowFile)>;
using write_data_func_t =
std::function<void(uint8_t* frame, uint16_t posInFrame, common::ValueVector* vector,
common::table_id_t commonTableID, DiskOverflowFile* diskOverflowFile)>;
uint32_t numElementsPerPage, DiskOverflowFile* diskOverflowFile)>;
using write_data_func_t = std::function<void(uint8_t* frame, uint16_t posInFrame,
common::ValueVector* vector, uint32_t posInVector, DiskOverflowFile* diskOverflowFile)>;

class Column : public BaseColumnOrList {
public:
// TODO(Guodong): Clean up column constructors.
// Currently extended by SERIAL column.
explicit Column(const common::DataType& dataType)
: BaseColumnOrList{dataType}, tableID{common::INVALID_TABLE_ID} {};
explicit Column(const common::DataType& dataType) : BaseColumnOrList{dataType} {};

Column(const StorageStructureIDAndFName& structureIDAndFName, const common::DataType& dataType,
BufferManager* bufferManager, WAL* wal)
Expand All @@ -34,15 +29,8 @@ class Column : public BaseColumnOrList {

Column(const StorageStructureIDAndFName& structureIDAndFName, const common::DataType& dataType,
size_t elementSize, BufferManager* bufferManager, WAL* wal)
: Column{structureIDAndFName, dataType, elementSize, bufferManager, wal,
common::INVALID_TABLE_ID} {};

// Extended by INTERNAL_ID column.
Column(const StorageStructureIDAndFName& structureIDAndFName, const common::DataType& dataType,
size_t elementSize, BufferManager* bufferManager, WAL* wal, common::table_id_t tableID)
: BaseColumnOrList{structureIDAndFName, dataType, elementSize, bufferManager,
true /*hasNULLBytes*/, wal},
tableID{tableID} {
true /*hasNULLBytes*/, wal} {
scanDataFunc = Column::scanValuesFromPage;
lookupDataFunc = Column::lookupValueFromPage;
writeDataFunc = Column::writeValueToPage;
Expand Down Expand Up @@ -80,12 +68,10 @@ class Column : public BaseColumnOrList {
private:
static void scanValuesFromPage(transaction::Transaction* transaction, uint8_t* frame,
PageElementCursor& pageCursor, common::ValueVector* resultVector, uint32_t posInVector,
uint32_t numElementsPerPage, uint32_t numValuesToRead, common::table_id_t commonTableID,
DiskOverflowFile* diskOverflowFile);
uint32_t numElementsPerPage, uint32_t numValuesToRead, DiskOverflowFile* diskOverflowFile);
static void lookupValueFromPage(transaction::Transaction* transaction, uint8_t* frame,
PageElementCursor& pageCursor, common::ValueVector* resultVector, uint32_t posInVector,
uint32_t numElementsPerPage, common::table_id_t commonTableID,
DiskOverflowFile* diskOverflowFile);
uint32_t numElementsPerPage, DiskOverflowFile* diskOverflowFile);
static void writeValueToPage(uint8_t* frame, uint16_t posInFrame, common::ValueVector* vector,
uint32_t posInVector, DiskOverflowFile* diskOverflowFile);

Expand All @@ -98,7 +84,6 @@ class Column : public BaseColumnOrList {
scan_data_func_t scanDataFunc;
lookup_data_func_t lookupDataFunc;
write_data_func_t writeDataFunc;
common::table_id_t tableID;
std::unique_ptr<DiskOverflowFile> diskOverflowFile;
};

Expand Down Expand Up @@ -163,12 +148,10 @@ class ListPropertyColumn : public PropertyColumnWithOverflow {
private:
static void scanListsFromPage(transaction::Transaction* transaction, uint8_t* frame,
PageElementCursor& pageCursor, common::ValueVector* resultVector, uint32_t posInVector,
uint32_t numElementsPerPage, uint32_t numValuesToRead, common::table_id_t commonTableID,
DiskOverflowFile* diskOverflowFile);
uint32_t numElementsPerPage, uint32_t numValuesToRead, DiskOverflowFile* diskOverflowFile);
static void lookupListFromPage(transaction::Transaction* transaction, uint8_t* frame,
PageElementCursor& pageCursor, common::ValueVector* resultVector, uint32_t posInVector,
uint32_t numElementsPerPage, common::table_id_t commonTableID,
DiskOverflowFile* diskOverflowFile);
uint32_t numElementsPerPage, DiskOverflowFile* diskOverflowFile);
static void writeListToPage(uint8_t* frame, uint16_t posInFrame, common::ValueVector* vector,
uint32_t posInVector, DiskOverflowFile* diskOverflowFile);
};
Expand All @@ -188,9 +171,9 @@ class StructPropertyColumn : public Column {
class InternalIDColumn : public Column {
public:
InternalIDColumn(const StorageStructureIDAndFName& structureIDAndFName,
BufferManager* bufferManager, WAL* wal, common::table_id_t tableID)
BufferManager* bufferManager, WAL* wal)
: Column{structureIDAndFName, common::DataType(common::INTERNAL_ID),
sizeof(common::offset_t), bufferManager, wal, tableID} {
sizeof(common::offset_t), bufferManager, wal} {
scanDataFunc = InternalIDColumn::scanInternalIDsFromPage;
lookupDataFunc = InternalIDColumn::lookupInternalIDFromPage;
writeDataFunc = InternalIDColumn::writeInternalIDToPage;
Expand All @@ -199,23 +182,14 @@ class InternalIDColumn : public Column {
private:
static void scanInternalIDsFromPage(transaction::Transaction* transaction, uint8_t* frame,
PageElementCursor& pageCursor, common::ValueVector* resultVector, uint32_t posInVector,
uint32_t numElementsPerPage, uint32_t numValuesToRead, common::table_id_t commonTableID,
DiskOverflowFile* diskOverflowFile);
uint32_t numElementsPerPage, uint32_t numValuesToRead, DiskOverflowFile* diskOverflowFile);
static void lookupInternalIDFromPage(transaction::Transaction* transaction, uint8_t* frame,
PageElementCursor& pageCursor, common::ValueVector* resultVector, uint32_t posInVector,
uint32_t numElementsPerPage, common::table_id_t commonTableID,
DiskOverflowFile* diskOverflowFile);
uint32_t numElementsPerPage, DiskOverflowFile* diskOverflowFile);
static void writeInternalIDToPage(uint8_t* frame, uint16_t posInFrame,
common::ValueVector* vector, uint32_t posInVector, DiskOverflowFile* diskOverflowFile);
};

class AdjColumn : public InternalIDColumn {
public:
AdjColumn(const StorageStructureIDAndFName& structureIDAndFName, common::table_id_t nbrTableID,
BufferManager* bufferManager, WAL* wal)
: InternalIDColumn{structureIDAndFName, bufferManager, wal, nbrTableID} {}
};

class SerialColumn : public Column {
public:
SerialColumn() : Column{common::DataType{common::SERIAL}} {}
Expand Down Expand Up @@ -247,14 +221,7 @@ class ColumnFactory {
return std::make_unique<ListPropertyColumn>(
structureIDAndFName, dataType, bufferManager, wal);
case common::INTERNAL_ID:
// RelID column in rel tables.
assert(structureIDAndFName.storageStructureID.storageStructureType ==
StorageStructureType::COLUMN &&
structureIDAndFName.storageStructureID.columnFileID.columnType ==
ColumnType::REL_PROPERTY_COLUMN);
return std::make_unique<InternalIDColumn>(structureIDAndFName, bufferManager, wal,
structureIDAndFName.storageStructureID.columnFileID.relPropertyColumnID
.relNodeTableAndDir.relTableID);
return std::make_unique<InternalIDColumn>(structureIDAndFName, bufferManager, wal);
case common::STRUCT:
return std::make_unique<StructPropertyColumn>(
structureIDAndFName, dataType, bufferManager, wal);
Expand Down
4 changes: 2 additions & 2 deletions src/include/storage/store/nodes_statistics_and_deleted_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NodeStatisticsAndDeletedIDs : public TableStatistics {
}

inline void setAdjListsAndColumns(
std::pair<std::vector<AdjLists*>, std::vector<AdjColumn*>> adjListsAndColumns_) {
std::pair<std::vector<AdjLists*>, std::vector<Column*>> adjListsAndColumns_) {
adjListsAndColumns = std::move(adjListsAndColumns_);
}

Expand Down Expand Up @@ -66,7 +66,7 @@ class NodeStatisticsAndDeletedIDs : public TableStatistics {
common::table_id_t tableID;
// Note: This is initialized explicitly through a call to setAdjListsAndColumns after
// construction.
std::pair<std::vector<AdjLists*>, std::vector<AdjColumn*>> adjListsAndColumns;
std::pair<std::vector<AdjLists*>, std::vector<Column*>> adjListsAndColumns;
std::vector<bool> hasDeletedNodesPerMorsel;
std::map<uint64_t, std::set<common::offset_t>> deletedNodeOffsetsPerMorsel;
};
Expand Down
29 changes: 16 additions & 13 deletions src/include/storage/store/rel_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ struct RelTableScanState {
class DirectedRelTableData {
public:
DirectedRelTableData(common::table_id_t tableID, common::table_id_t boundTableID,
common::RelDataDirection direction, ListsUpdatesStore* listsUpdatesStore,
BufferManager& bufferManager, bool isSingleMultiplicityInDirection)
: tableID{tableID}, boundTableID{boundTableID}, direction{direction},
listsUpdatesStore{listsUpdatesStore}, bufferManager{bufferManager},
common::table_id_t nbrTableID, common::RelDataDirection direction,
ListsUpdatesStore* listsUpdatesStore, BufferManager& bufferManager,
bool isSingleMultiplicityInDirection)
: tableID{tableID}, boundTableID{boundTableID}, nbrTableID{nbrTableID},
direction{direction}, listsUpdatesStore{listsUpdatesStore}, bufferManager{bufferManager},
isSingleMultiplicityInDirection{isSingleMultiplicityInDirection} {}

inline uint32_t getNumPropertyLists() { return propertyLists.size(); }
Expand All @@ -83,15 +84,13 @@ class DirectedRelTableData {
->getListOffset(nodeID.offset, relID) :
UINT64_MAX;
}
inline AdjColumn* getAdjColumn() const { return adjColumn.get(); }
inline Column* getAdjColumn() const { return adjColumn.get(); }
inline AdjLists* getAdjLists() const { return adjLists.get(); }
inline bool isSingleMultiplicity() const { return isSingleMultiplicityInDirection; }

void initializeData(catalog::RelTableSchema* tableSchema, WAL* wal);
void initializeColumns(
catalog::RelTableSchema* tableSchema, BufferManager& bufferManager, WAL* wal);
void initializeLists(
catalog::RelTableSchema* tableSchema, BufferManager& bufferManager, WAL* wal);
void initializeColumns(catalog::RelTableSchema* tableSchema, WAL* wal);
void initializeLists(catalog::RelTableSchema* tableSchema, WAL* wal);
Column* getPropertyColumn(common::property_id_t propertyID);
Lists* getPropertyLists(common::property_id_t propertyID);

Expand All @@ -104,7 +103,7 @@ class DirectedRelTableData {
scanLists(transaction, scanState, inNodeIDVector, outputVectors);
}
}
inline bool isBoundTable(common::table_id_t tableID) const { return tableID == boundTableID; }
inline bool isBoundTable(common::table_id_t tableID_) const { return tableID_ == boundTableID; }

void insertRel(common::ValueVector* boundVector, common::ValueVector* nbrVector,
const std::vector<common::ValueVector*>& relPropertyVectors);
Expand All @@ -126,14 +125,18 @@ class DirectedRelTableData {
common::ValueVector* inNodeIDVector,
const std::vector<common::ValueVector*>& outputVectors);

void fillNbrTableIDs(common::ValueVector* vector);
void fillRelTableIDs(common::ValueVector* vector);

private:
// TODO(Guodong): remove the distinction between AdjColumn and Column, also AdjLists and Lists.
std::unordered_map<common::property_id_t, std::unique_ptr<Column>> propertyColumns;
std::unique_ptr<AdjColumn> adjColumn;
std::unique_ptr<Column> adjColumn;
std::unordered_map<common::property_id_t, std::unique_ptr<Lists>> propertyLists;
std::unique_ptr<AdjLists> adjLists;
common::table_id_t tableID;
common::table_id_t boundTableID;
common::table_id_t nbrTableID;
common::RelDataDirection direction;
ListsUpdatesStore* listsUpdatesStore;
BufferManager& bufferManager;
Expand Down Expand Up @@ -166,7 +169,7 @@ class RelTable {
fwdRelTableData->getNumPropertyLists() :
bwdRelTableData->getNumPropertyLists();
}
inline AdjColumn* getAdjColumn(common::RelDataDirection relDirection) {
inline Column* getAdjColumn(common::RelDataDirection relDirection) {
return relDirection == common::RelDataDirection::FWD ? fwdRelTableData->getAdjColumn() :
bwdRelTableData->getAdjColumn();
}
Expand All @@ -191,7 +194,7 @@ class RelTable {
}

std::vector<AdjLists*> getAllAdjLists(common::table_id_t boundTableID);
std::vector<AdjColumn*> getAllAdjColumns(common::table_id_t boundTableID);
std::vector<Column*> getAllAdjColumns(common::table_id_t boundTableID);

void prepareCommitOrRollbackIfNecessary(bool isCommit);
void checkpointInMemoryIfNecessary();
Expand Down
4 changes: 2 additions & 2 deletions src/include/storage/store/rels_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class RelsStore {
common::table_id_t relTableID, uint64_t propertyIdx) const {
return relTables.at(relTableID)->getPropertyLists(relDirection, propertyIdx);
}
inline AdjColumn* getAdjColumn(
inline Column* getAdjColumn(
common::RelDataDirection relDirection, common::table_id_t relTableID) const {
return relTables.at(relTableID)->getAdjColumn(relDirection);
}
Expand Down Expand Up @@ -66,7 +66,7 @@ class RelsStore {
return relTables.at(relTableID)->isSingleMultiplicityInDirection(relDirection);
}

std::pair<std::vector<AdjLists*>, std::vector<AdjColumn*>> getAdjListsAndColumns(
std::pair<std::vector<AdjLists*>, std::vector<Column*>> getAdjListsAndColumns(
common::table_id_t boundTableID) const;

private:
Expand Down
Loading