indexes WIP
This commit is contained in:
23
usql_ddl.cpp
23
usql_ddl.cpp
@@ -1,6 +1,5 @@
|
||||
#include "usql.h"
|
||||
#include "exception.h"
|
||||
#include "ml_date.h"
|
||||
#include "ml_string.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -20,6 +19,28 @@ std::unique_ptr<Table> USql::execute_create_table(CreateTableNode &node) {
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_create_index(CreateIndexNode &node) {
|
||||
Table *table_def = find_table(node.table_name); // throws exception if not found
|
||||
ColDefNode col_def = table_def->get_column_def(node.column_name); // throws exception if not found
|
||||
|
||||
if (table_def->get_index(node.index_name) != nullptr) throw Exception("index already exists");
|
||||
if (col_def.null) throw Exception("index on not null supported only");
|
||||
if (table_def->get_index_for_column(node.column_name) != nullptr) throw Exception("column is already indexed");
|
||||
|
||||
IndexedDataType type;
|
||||
if (col_def.type == ColumnType::integer_type) type = IndexedDataType::integer;
|
||||
else if (col_def.type == ColumnType::varchar_type) type = IndexedDataType::string;
|
||||
else throw Exception("creating index on unsupported type");
|
||||
|
||||
Index<IndexValue> i{node.index_name, node.column_name, type};
|
||||
table_def->create_index(i);
|
||||
|
||||
table_def->index_rows(node.index_name);
|
||||
|
||||
return create_stmt_result_table(0, "index created", 0);
|
||||
}
|
||||
|
||||
|
||||
std::unique_ptr<Table> USql::execute_create_table_as_table(CreateTableAsSelectNode &node) {
|
||||
check_table_not_exists(node.table_name);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user