indexes WIP

This commit is contained in:
2021-12-13 22:08:27 +01:00
parent 411f0fd48c
commit 7ae4ef53f9
12 changed files with 410 additions and 272 deletions

43
table.h
View File

@@ -4,6 +4,7 @@
#include "parser.h"
#include "row.h"
#include <utility>
#include <vector>
#include <iterator> // For std::forward_iterator_tag
@@ -26,14 +27,15 @@ struct Table {
[[nodiscard]] int columns_count() const { return (int) m_col_defs.size(); };
[[nodiscard]] size_t rows_count() const { return m_rows.size(); };
Row& create_empty_row();
void commit_row(const Row &row);
void commit_copy_of_row(const Row &row);
Row& get_row(int rowid) { return m_rows[rowid]; };
[[nodiscard]] size_t get_rowid(const Row &row) const;
Row &create_empty_row();
void commit_row(Row &row);
void commit_copy_of_row(Row &row);
static void validate_column(const ColDefNode *col_def, ValueNode *col_val);
static void validate_column(const ColDefNode *col_def, ColValue &col_val);
void validate_row(const Row &row);
void validate_row(Row &row);
std::string csv_string();
int load_csv_string(const std::string &content);
@@ -52,19 +54,36 @@ struct Table {
void create_row_from_vector(const std::vector<ColDefNode> &colDefs, const std::vector<std::string> &csv_line);
void create_index(const Index<IndexValue>& index);
void drop_index(const std::string &column);
void index_row(Index<IndexValue> &index, const Row &row, const size_t rowid);
void index_row(const Row &row, const size_t rowid);
bool drop_index(const std::string &index_name);
static void index_row(Index<IndexValue> &index, const ColDefNode &col_def, const Row &row, size_t rowid);
static void unindex_row(Index<IndexValue> &index, const ColDefNode &col_def, const Row &row, size_t rowid);
static void reindex_row(Index<IndexValue> &index, const ColDefNode &col_def, const Row &old_row, const Row &new_row, size_t rowid);
void index_row(const Row &row);
void unindex_row(const Row &row);
void reindex_row(const Row &old_row, const Row &new_row);
void index_rows(const std::string &index_name);
Index<IndexValue> * get_index(const std::string &index_name);
Index<IndexValue> * get_index_for_column(const std::string &col_name);
std::vector<int> index_search(const std::string &col_name, IndexValue key);
typedef std::vector<Row>::iterator iterator;
iterator fs_begin() { return m_rows.begin(); }
iterator fs_end() { return m_rows.end(); }
struct rows_scanner {
explicit rows_scanner(Table *tbl) : m_use_rowids(false), m_table(tbl), m_fscan_itr(tbl->m_rows.begin()) {}
rows_scanner(Table *tbl, std::vector<rowid_t> rowids) : m_use_rowids(true), m_table(tbl), m_rowids(std::move(rowids)), m_rowids_idx(0) {}
Row *next();
private:
bool m_use_rowids;
Table * m_table;
std::vector<Row>::iterator m_fscan_itr;
std::vector<rowid_t> m_rowids; // TODO long here
size_t m_rowids_idx{};
};
};
} // namespace