Skip to content

Commit

Permalink
Merge pull request #2075 from kuzudb/refactor-storage
Browse files Browse the repository at this point in the history
Reorganize stat files
  • Loading branch information
ray6080 committed Sep 24, 2023
2 parents 57d37b2 + 819b0ca commit c22396f
Show file tree
Hide file tree
Showing 47 changed files with 816 additions and 726 deletions.
14 changes: 7 additions & 7 deletions src/include/planner/join_order/cardinality_estimator.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

#include "binder/query/query_graph.h"
#include "planner/operator/logical_plan.h"
#include "storage/stats/nodes_statistics_and_deleted_ids.h"
#include "storage/stats/rels_statistics.h"
#include "storage/stats/nodes_store_statistics.h"
#include "storage/stats/rels_store_statistics.h"

namespace kuzu {
namespace planner {

class CardinalityEstimator {
public:
CardinalityEstimator(const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics)
CardinalityEstimator(const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics,
const storage::RelsStoreStats& relsStatistics)
: nodesStatistics{nodesStatistics}, relsStatistics{relsStatistics} {}

void initNodeIDDom(binder::QueryGraph* queryGraph);
Expand All @@ -37,7 +37,7 @@ class CardinalityEstimator {
nodeIDName2dom.insert({key, getNumNodes(node)});
}
}
uint64_t getNodeIDDom(const std::string& nodeIDName) {
inline uint64_t getNodeIDDom(const std::string& nodeIDName) {
assert(nodeIDName2dom.contains(nodeIDName));
return nodeIDName2dom.at(nodeIDName);
}
Expand All @@ -46,8 +46,8 @@ class CardinalityEstimator {
uint64_t getNumRels(const binder::RelExpression& rel);

private:
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics;
const storage::RelsStatistics& relsStatistics;
const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics;
const storage::RelsStoreStats& relsStatistics;
// The domain of nodeID is defined as the number of unique value of nodeID, i.e. num nodes.
std::unordered_map<std::string, uint64_t> nodeIDName2dom;
};
Expand Down
24 changes: 12 additions & 12 deletions src/include/planner/planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ namespace planner {
class Planner {
public:
static std::unique_ptr<LogicalPlan> getBestPlan(const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);
const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics,
const storage::RelsStoreStats& relsStatistics, const BoundStatement& statement);

static std::vector<std::unique_ptr<LogicalPlan>> getAllPlans(const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);
const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics,
const storage::RelsStoreStats& relsStatistics, const BoundStatement& statement);

private:
static std::unique_ptr<LogicalPlan> planCreateTable(const BoundStatement& statement);
Expand All @@ -33,26 +33,26 @@ class Planner {
static std::unique_ptr<LogicalPlan> planCommentOn(const BoundStatement& statement);

static std::unique_ptr<LogicalPlan> planExplain(const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);
const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics,
const storage::RelsStoreStats& relsStatistics, const BoundStatement& statement);

static std::unique_ptr<LogicalPlan> planCreateMacro(const BoundStatement& statement);

static std::unique_ptr<LogicalPlan> planTransaction(const BoundStatement& statement);

static std::vector<std::unique_ptr<LogicalPlan>> getAllQueryPlans(
const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);
const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics,
const storage::RelsStoreStats& relsStatistics, const BoundStatement& statement);

static std::vector<std::unique_ptr<LogicalPlan>> getAllExplainPlans(
const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);
const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics,
const storage::RelsStoreStats& relsStatistics, const BoundStatement& statement);

static std::unique_ptr<LogicalPlan> planCopyTo(const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics, const BoundStatement& statement);
const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics,
const storage::RelsStoreStats& relsStatistics, const BoundStatement& statement);

static std::unique_ptr<LogicalPlan> planCopyFrom(const BoundStatement& statement);

Expand Down
4 changes: 2 additions & 2 deletions src/include/planner/query_planner.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ class QueryPlanner {

public:
QueryPlanner(const catalog::Catalog& catalog,
const storage::NodesStatisticsAndDeletedIDs& nodesStatistics,
const storage::RelsStatistics& relsStatistics)
const storage::NodesStoreStatsAndDeletedIDs& nodesStatistics,
const storage::RelsStoreStats& relsStatistics)
: catalog{catalog} {
cardinalityEstimator =
std::make_unique<CardinalityEstimator>(nodesStatistics, relsStatistics);
Expand Down
6 changes: 3 additions & 3 deletions src/include/processor/operator/ddl/create_node_table.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "processor/operator/ddl/ddl.h"
#include "storage/stats/nodes_statistics_and_deleted_ids.h"
#include "storage/stats/nodes_store_statistics.h"
#include "storage/store/nodes_store.h"

namespace kuzu {
Expand All @@ -10,7 +10,7 @@ namespace processor {
class CreateNodeTable : public DDL {
public:
CreateNodeTable(catalog::Catalog* catalog, storage::StorageManager* storageManager,
storage::NodesStatisticsAndDeletedIDs* nodesStatistics,
storage::NodesStoreStatsAndDeletedIDs* nodesStatistics,
std::unique_ptr<binder::BoundCreateTableInfo> info, const DataPos& outputPos, uint32_t id,
const std::string& paramsString)
: DDL{PhysicalOperatorType::CREATE_NODE_TABLE, catalog, outputPos, id, paramsString},
Expand All @@ -27,7 +27,7 @@ class CreateNodeTable : public DDL {

private:
storage::StorageManager* storageManager;
storage::NodesStatisticsAndDeletedIDs* nodesStatistics;
storage::NodesStoreStatsAndDeletedIDs* nodesStatistics;
std::unique_ptr<binder::BoundCreateTableInfo> info;
};

Expand Down
8 changes: 4 additions & 4 deletions src/include/processor/operator/ddl/create_rdf_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace processor {
class CreateRdfGraph : public DDL {
public:
CreateRdfGraph(catalog::Catalog* catalog, storage::StorageManager* storageManager,
storage::NodesStatisticsAndDeletedIDs* nodesStatistics,
storage::RelsStatistics* relsStatistics, std::unique_ptr<binder::BoundCreateTableInfo> info,
storage::NodesStoreStatsAndDeletedIDs* nodesStatistics,
storage::RelsStoreStats* relsStatistics, std::unique_ptr<binder::BoundCreateTableInfo> info,
const DataPos& outputPos, uint32_t id, const std::string& paramsString)
: DDL{PhysicalOperatorType::CREATE_RDF_GRAPH, catalog, outputPos, id, paramsString},
storageManager{storageManager}, nodesStatistics{nodesStatistics},
Expand All @@ -27,8 +27,8 @@ class CreateRdfGraph : public DDL {

private:
storage::StorageManager* storageManager;
storage::NodesStatisticsAndDeletedIDs* nodesStatistics;
storage::RelsStatistics* relsStatistics;
storage::NodesStoreStatsAndDeletedIDs* nodesStatistics;
storage::RelsStoreStats* relsStatistics;
std::unique_ptr<binder::BoundCreateTableInfo> info;
};

Expand Down
6 changes: 3 additions & 3 deletions src/include/processor/operator/ddl/create_rel_table.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include "processor/operator/ddl/ddl.h"
#include "storage/stats/rels_statistics.h"
#include "storage/stats/rels_store_statistics.h"

namespace kuzu {
namespace processor {

class CreateRelTable : public DDL {
public:
CreateRelTable(catalog::Catalog* catalog, storage::RelsStatistics* relsStatistics,
CreateRelTable(catalog::Catalog* catalog, storage::RelsStoreStats* relsStatistics,
std::unique_ptr<binder::BoundCreateTableInfo> info, const DataPos& outputPos, uint32_t id,
const std::string& paramsString)
: DDL{PhysicalOperatorType::CREATE_REL_TABLE, catalog, outputPos, id, paramsString},
Expand All @@ -24,7 +24,7 @@ class CreateRelTable : public DDL {
}

private:
storage::RelsStatistics* relsStatistics;
storage::RelsStoreStats* relsStatistics;
std::unique_ptr<binder::BoundCreateTableInfo> info;
};

Expand Down
6 changes: 3 additions & 3 deletions src/include/processor/operator/ddl/create_rel_table_group.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#pragma once

#include "processor/operator/ddl/ddl.h"
#include "storage/stats/rels_statistics.h"
#include "storage/stats/rels_store_statistics.h"

namespace kuzu {
namespace processor {

class CreateRelTableGroup : public DDL {
public:
CreateRelTableGroup(catalog::Catalog* catalog, storage::RelsStatistics* relsStatistics,
CreateRelTableGroup(catalog::Catalog* catalog, storage::RelsStoreStats* relsStatistics,
std::unique_ptr<binder::BoundCreateTableInfo> info, const DataPos& outputPos, uint32_t id,
const std::string& paramsString)
: DDL{PhysicalOperatorType::CREATE_REL_TABLE, catalog, outputPos, id, paramsString},
Expand All @@ -24,7 +24,7 @@ class CreateRelTableGroup : public DDL {
}

private:
storage::RelsStatistics* relsStatistics;
storage::RelsStoreStats* relsStatistics;
std::unique_ptr<binder::BoundCreateTableInfo> info;
};

Expand Down
6 changes: 1 addition & 5 deletions src/include/processor/operator/persistent/copy_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ class CopyNode : public Sink {
storage::NodeTable* table, storage::NodeGroup* nodeGroup, bool isCopyTurtle);

private:
inline bool isCopyAllowed() const {
auto nodesStatistics = copyNodeInfo.table->getNodeStatisticsAndDeletedIDs();
return nodesStatistics->getNodeStatisticsAndDeletedIDs(copyNodeInfo.table->getTableID())
->getNumTuples() == 0;
}
bool isCopyAllowed() const;

static void populatePKIndex(storage::PrimaryKeyIndexBuilder* pkIndex,
storage::ColumnChunk* chunk, common::offset_t startNodeOffset, common::offset_t numNodes);
Expand Down
6 changes: 3 additions & 3 deletions src/include/processor/operator/persistent/copy_rel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "storage/in_mem_storage_structure/in_mem_column.h"
#include "storage/in_mem_storage_structure/in_mem_column_chunk.h"
#include "storage/in_mem_storage_structure/in_mem_lists.h"
#include "storage/stats/rels_statistics.h"
#include "storage/stats/rels_store_statistics.h"

namespace kuzu {
namespace processor {
Expand Down Expand Up @@ -70,7 +70,7 @@ class CopyRelSharedState {
friend class CopyRelLists;

public:
CopyRelSharedState(common::table_id_t tableID, storage::RelsStatistics* relsStatistics,
CopyRelSharedState(common::table_id_t tableID, storage::RelsStoreStats* relsStatistics,
std::unique_ptr<DirectedInMemRelData> fwdRelData,
std::unique_ptr<DirectedInMemRelData> bwdRelData, storage::MemoryManager* memoryManager);

Expand All @@ -85,7 +85,7 @@ class CopyRelSharedState {
private:
std::mutex mtx;
common::table_id_t tableID;
storage::RelsStatistics* relsStatistics;
storage::RelsStoreStats* relsStatistics;
std::unique_ptr<DirectedInMemRelData> fwdRelData;
std::unique_ptr<DirectedInMemRelData> bwdRelData;
std::shared_ptr<FactorizedTable> fTable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "processor/operator/persistent/copy_rel.h"
#include "processor/operator/sink.h"
#include "storage/index/hash_index.h"
#include "storage/stats/rels_statistics.h"
#include "storage/stats/rels_store_statistics.h"

namespace kuzu {
namespace processor {
Expand Down
6 changes: 3 additions & 3 deletions src/include/processor/operator/persistent/delete_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class RelDeleteExecutor {

class SingleLabelRelDeleteExecutor : public RelDeleteExecutor {
public:
SingleLabelRelDeleteExecutor(storage::RelsStatistics* relsStatistic, storage::RelTable* table,
SingleLabelRelDeleteExecutor(storage::RelsStoreStats* relsStatistic, storage::RelTable* table,
const DataPos& srcNodeIDPos, const DataPos& dstNodeIDPos, const DataPos& relIDPos)
: RelDeleteExecutor(srcNodeIDPos, dstNodeIDPos, relIDPos),
relsStatistic{relsStatistic}, table{table} {}
Expand All @@ -103,12 +103,12 @@ class SingleLabelRelDeleteExecutor : public RelDeleteExecutor {
}

private:
storage::RelsStatistics* relsStatistic;
storage::RelsStoreStats* relsStatistic;
storage::RelTable* table;
};

class MultiLabelRelDeleteExecutor : public RelDeleteExecutor {
using rel_table_statistic_pair = std::pair<storage::RelTable*, storage::RelsStatistics*>;
using rel_table_statistic_pair = std::pair<storage::RelTable*, storage::RelsStoreStats*>;

public:
MultiLabelRelDeleteExecutor(
Expand Down
4 changes: 2 additions & 2 deletions src/include/processor/operator/persistent/insert_executor.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class NodeInsertExecutor {

class RelInsertExecutor {
public:
RelInsertExecutor(storage::RelsStatistics& relsStatistics, storage::RelTable* table,
RelInsertExecutor(storage::RelsStoreStats& relsStatistics, storage::RelTable* table,
const DataPos& srcNodePos, const DataPos& dstNodePos,
std::vector<DataPos> propertyLhsPositions,
std::vector<std::unique_ptr<evaluator::ExpressionEvaluator>> propertyRhsEvaluators)
Expand All @@ -65,7 +65,7 @@ class RelInsertExecutor {
const std::vector<std::unique_ptr<RelInsertExecutor>>& executors);

private:
storage::RelsStatistics& relsStatistics;
storage::RelsStoreStats& relsStatistics;
storage::RelTable* table;
DataPos srcNodePos;
DataPos dstNodePos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "processor/operator/filtering_operator.h"
#include "processor/operator/scan/scan_rel_table.h"
#include "storage/stats/rels_statistics.h"
#include "storage/stats/rels_store_statistics.h"

namespace kuzu {
namespace processor {
Expand Down
2 changes: 1 addition & 1 deletion src/include/processor/plan_mapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "planner/operator/logical_plan.h"
#include "processor/operator/result_collector.h"
#include "processor/physical_plan.h"
#include "storage/stats/nodes_statistics_and_deleted_ids.h"
#include "storage/stats/node_table_statistics.h"
#include "storage/storage_manager.h"

namespace kuzu {
Expand Down
28 changes: 28 additions & 0 deletions src/include/storage/stats/metadata_dah_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include "common/types/types.h"

namespace kuzu {
namespace storage {

// DAH is the abbreviation for Disk Array Header.
struct MetadataDAHInfo {
common::page_idx_t dataDAHPageIdx = common::INVALID_PAGE_IDX;
common::page_idx_t nullDAHPageIdx = common::INVALID_PAGE_IDX;
std::vector<std::unique_ptr<MetadataDAHInfo>> childrenInfos;

MetadataDAHInfo() : MetadataDAHInfo{common::INVALID_PAGE_IDX, common::INVALID_PAGE_IDX} {}
MetadataDAHInfo(common::page_idx_t dataDAHPageIdx)
: MetadataDAHInfo{dataDAHPageIdx, common::INVALID_PAGE_IDX} {}
MetadataDAHInfo(common::page_idx_t dataDAHPageIdx, common::page_idx_t nullDAHPageIdx)
: dataDAHPageIdx{dataDAHPageIdx}, nullDAHPageIdx{nullDAHPageIdx} {}

std::unique_ptr<MetadataDAHInfo> copy();

void serialize(common::FileInfo* fileInfo, uint64_t& offset) const;
static std::unique_ptr<MetadataDAHInfo> deserialize(
common::FileInfo* fileInfo, uint64_t& offset);
};

} // namespace storage
} // namespace kuzu
Loading

0 comments on commit c22396f

Please sign in to comment.