indexes WIP

This commit is contained in:
2021-11-17 15:35:57 +01:00
parent cc639ee891
commit 411f0fd48c
25 changed files with 609 additions and 807 deletions

36
usql.h
View File

@@ -1,7 +1,9 @@
#pragma once
#include "settings.h"
#include "parser.h"
#include "table.h"
#include "index.h"
#include <string>
#include <list>
@@ -19,6 +21,7 @@ private:
std::unique_ptr<Table> execute(Node &node);
std::unique_ptr<Table> execute_create_table(CreateTableNode &node);
std::unique_ptr<Table> execute_create_index(CreateIndexNode &node);
std::unique_ptr<Table> execute_create_table_as_table(CreateTableAsSelectNode &node);
std::unique_ptr<Table> execute_load(LoadIntoTableNode &node);
std::unique_ptr<Table> execute_save(SaveTableNode &node);
@@ -27,7 +30,7 @@ private:
static std::unique_ptr<Table> execute_show(ShowNode &node);
std::unique_ptr<Table> execute_insert_into_table(InsertIntoTableNode &node);
std::unique_ptr<Table> execute_select(SelectFromTableNode &node);
std::unique_ptr<Table> execute_select(SelectFromTableNode &node) const;
std::unique_ptr<Table> execute_delete(DeleteFromTableNode &node);
std::unique_ptr<Table> execute_update(UpdateTableNode &node);
@@ -37,7 +40,7 @@ private:
static std::unique_ptr<ValueNode> eval_value_node(Table *table, Row &row, Node *node, ColDefNode *col_def_node, ColValue *agg_func_value);
static std::unique_ptr<ValueNode> eval_database_value_node(Table *table, Row &row, Node *node);
static std::unique_ptr<ValueNode> eval_literal_value_node(Table *table, Row &row, Node *node);
static std::unique_ptr<ValueNode> eval_literal_value_node(Row &row, Node *node);
static std::unique_ptr<ValueNode> eval_function_value_node(Table *table, Row &row, Node *node, ColDefNode *col_def_node, ColValue *agg_func_value);
@@ -50,22 +53,22 @@ private:
static std::tuple<int, ColDefNode> get_column_definition(Table *table, SelectColNode *select_col_node, int col_order);
static ColDefNode get_db_column_definition(Table *table, Node *node);
static std::tuple<int, ColDefNode> get_node_definition(Table *table, Node *select_col_node, const std::string & col_name, int col_order);
Table *find_table(const std::string &name);
[[nodiscard]] Table *find_table(const std::string &name) const;
void check_table_not_exists(const std::string &name);
void check_table_not_exists(const std::string &name) const;
private:
Parser m_parser;
std::list<Table> m_tables;
static void execute_distinct(SelectFromTableNode &node, Table *result) ;
static void execute_order_by(SelectFromTableNode &node, Table *table, Table *result) ;
static void execute_offset_limit(OffsetLimitNode &node, Table *result) ;
static void execute_distinct(SelectFromTableNode &node, Table *result);
static void execute_order_by(SelectFromTableNode &node, Table *table, Table *result);
static void execute_offset_limit(OffsetLimitNode &node, Table *result);
void expand_asterix_char(SelectFromTableNode &node, Table *table) const;
void setup_order_columns(std::vector<ColOrderNode> &node, Table *table) const;
static void expand_asterix_char(SelectFromTableNode &node, Table *table) ;
static void setup_order_columns(std::vector<ColOrderNode> &node, Table *table) ;
bool check_for_aggregate_only_functions(SelectFromTableNode &node, int result_cols_cnt) const;
static bool check_for_aggregate_only_functions(SelectFromTableNode &node, size_t result_cols_cnt) ;
static std::unique_ptr<ValueNode> lower_function(const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars);
static std::unique_ptr<ValueNode> upper_function(const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars);
@@ -77,8 +80,17 @@ private:
static std::unique_ptr<ValueNode> max_function(const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars, const ColDefNode *col_def_node, ColValue *agg_func_value);
static std::unique_ptr<ValueNode> min_function(const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars, const ColDefNode *col_def_node, ColValue *agg_func_value);
static std::unique_ptr<ValueNode>
count_function(ColValue *agg_func_value, const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars);
static std::unique_ptr<ValueNode> count_function(ColValue *agg_func_value, const std::vector<std::unique_ptr<ValueNode>> &evaluatedPars);
static void evalRowWhere(SelectFromTableNode &where_node,
Table *src_table, Row *src_row,
Table *rslt_table, Row *rslt_row,
const std::vector<ColDefNode> &rslt_tbl_col_defs, const std::vector<int> &src_table_col_index,
bool is_aggregated) ;
std::pair<bool, std::vector<int>> probe_index_scan(const Node *where, Table *table) const;
std::pair<bool, std::vector<int>> look_for_usable_index(const Node *where, Table *table) const;
bool normalize_where(const Node *node) const;
};
} // namespace