1#include "duckdb/execution/operator/schema/physical_create_index.hpp"
2
3#include "duckdb/catalog/catalog_entry/index_catalog_entry.hpp"
4#include "duckdb/catalog/catalog_entry/schema_catalog_entry.hpp"
5#include "duckdb/catalog/catalog_entry/table_catalog_entry.hpp"
6#include "duckdb/execution/expression_executor.hpp"
7
8using namespace std;
9
10namespace duckdb {
11
12void PhysicalCreateIndex::GetChunkInternal(ClientContext &context, DataChunk &chunk, PhysicalOperatorState *state) {
13 if (column_ids.size() == 0) {
14 throw NotImplementedException("CREATE INDEX does not refer to any columns in the base table!");
15 }
16
17 auto &schema = *table.schema;
18 auto index_entry = (IndexCatalogEntry *)schema.CreateIndex(context, info.get());
19 if (!index_entry) {
20 // index already exists, but error ignored because of IF NOT EXISTS
21 return;
22 }
23
24 unique_ptr<Index> index;
25 switch (info->index_type) {
26 case IndexType::ART: {
27 index = make_unique<ART>(column_ids, move(unbound_expressions), info->unique);
28 break;
29 }
30 default:
31 assert(0);
32 throw NotImplementedException("Unimplemented index type");
33 }
34 index_entry->index = index.get();
35 index_entry->info = table.storage->info;
36 table.storage->AddIndex(move(index), expressions);
37
38 chunk.SetCardinality(0);
39 state->finished = true;
40}
41
42} // namespace duckdb
43