Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit d56b3e5

Browse files
pmenonapavlo
authored andcommitted
Support creation of ART indexes through PSQL
1 parent ca8366c commit d56b3e5

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

src/common/internal_types.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/common/internal_types.cpp
88
//
9-
// Copyright (c) 2015-2017, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -18,7 +18,6 @@
1818
#include "common/internal_types.h"
1919
#include "common/logger.h"
2020
#include "common/macros.h"
21-
#include "type/value_factory.h"
2221
#include "parser/sql_statement.h"
2322
#include "parser/statements.h"
2423
#include "util/string_util.h"
@@ -1108,6 +1107,8 @@ IndexType StringToIndexType(const std::string &str) {
11081107
return IndexType::HASH;
11091108
} else if (upper_str == "SKIPLIST") {
11101109
return IndexType::SKIPLIST;
1110+
} else if (upper_str == "ART") {
1111+
return IndexType::ART;
11111112
} else {
11121113
throw ConversionException(StringUtil::Format(
11131114
"No IndexType conversion from string '%s'", upper_str.c_str()));

src/include/index/index_factory.h

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
// Identification: src/include/index/index_factory.h
88
//
9-
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -19,33 +19,26 @@
1919
namespace peloton {
2020
namespace index {
2121

22-
//===--------------------------------------------------------------------===//
23-
// IndexFactory
24-
//===--------------------------------------------------------------------===//
25-
22+
//===----------------------------------------------------------------------===//
23+
//
24+
// This is a factory for all index structures supported in Peloton
25+
//
26+
//===----------------------------------------------------------------------===//
2627
class IndexFactory {
2728
public:
28-
// Get an index with required attributes
29+
/// Get an index with required attributes
2930
static Index *GetIndex(IndexMetadata *metadata);
3031

3132
private:
3233
static std::string GetInfo(IndexMetadata *metadata,
33-
std::string comparatorType);
34-
35-
//===--------------------------------------------------------------------===//
36-
// PELOTON::BWTREE
37-
//===--------------------------------------------------------------------===//
34+
const std::string &comparator_type);
3835

36+
/// BwTree factory methods
3937
static Index *GetBwTreeIntsKeyIndex(IndexMetadata *metadata);
40-
4138
static Index *GetBwTreeGenericKeyIndex(IndexMetadata *metadata);
4239

43-
//===--------------------------------------------------------------------===//
44-
// PELOTON::SKIPLIST
45-
//===--------------------------------------------------------------------===//
46-
40+
/// SkipList factory methods
4741
static Index *GetSkipListIntsKeyIndex(IndexMetadata *metadata);
48-
4942
static Index *GetSkipListGenericKeyIndex(IndexMetadata *metadata);
5043
};
5144

src/index/index_factory.cpp

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
//
77
// Identification: src/index/index_factory.cpp
88
//
9-
// Copyright (c) 2015-16, Carnegie Mellon University Database Group
9+
// Copyright (c) 2015-2018, Carnegie Mellon University Database Group
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#include <iostream>
13+
#include "index/index_factory.h"
1414

1515
#include <sstream>
1616

1717
#include "common/logger.h"
1818
#include "common/macros.h"
19+
#include "index/art_index.h"
1920
#include "index/bwtree_index.h"
20-
#include "index/index_factory.h"
2121
#include "index/index_key.h"
2222
#include "index/skiplist_index.h"
2323

@@ -37,9 +37,10 @@ Index *IndexFactory::GetIndex(IndexMetadata *metadata) {
3737
// If so, then we can rock a specialized IntsKeyComparator
3838
// that is faster than the FastGenericComparator
3939
bool ints_only = true;
40-
for (auto column : metadata->key_schema->GetColumns()) {
40+
for (const auto &column : metadata->key_schema->GetColumns()) {
4141
auto col_type = column.GetType();
42-
if (col_type != type::TypeId::TINYINT && col_type != type::TypeId::SMALLINT &&
42+
if (col_type != type::TypeId::TINYINT &&
43+
col_type != type::TypeId::SMALLINT &&
4344
col_type != type::TypeId::INTEGER && col_type != type::TypeId::BIGINT) {
4445
ints_only = false;
4546
break;
@@ -66,19 +67,25 @@ Index *IndexFactory::GetIndex(IndexMetadata *metadata) {
6667
index = IndexFactory::GetBwTreeGenericKeyIndex(metadata);
6768
}
6869

69-
// -----------------------
70-
// SKIP-LIST
71-
// -----------------------
70+
// -----------------------
71+
// SKIP-LIST
72+
// -----------------------
7273
} else if (index_type == IndexType::SKIPLIST) {
7374
if (ints_only) {
7475
index = IndexFactory::GetSkipListIntsKeyIndex(metadata);
7576
} else {
7677
index = IndexFactory::GetSkipListGenericKeyIndex(metadata);
7778
}
7879

79-
// -----------------------
80-
// ERROR
81-
// -----------------------
80+
// -----------------------
81+
// Art
82+
// -----------------------
83+
} else if (index_type == IndexType::ART) {
84+
index = new ArtIndex(metadata);
85+
86+
// -----------------------
87+
// ERROR
88+
// -----------------------
8289
} else {
8390
throw IndexException("Unsupported index scheme.");
8491
}
@@ -142,7 +149,8 @@ Index *IndexFactory::GetBwTreeIntsKeyIndex(IndexMetadata *metadata) {
142149
#ifdef LOG_TRACE_ENABLED
143150
LOG_TRACE("%s", IndexFactory::GetInfo(metadata, comparatorType).c_str());
144151
#endif
145-
return (index);
152+
153+
return index;
146154
}
147155

148156
Index *IndexFactory::GetBwTreeGenericKeyIndex(IndexMetadata *metadata) {
@@ -213,7 +221,8 @@ Index *IndexFactory::GetBwTreeGenericKeyIndex(IndexMetadata *metadata) {
213221
#ifdef LOG_TRACE_ENABLED
214222
LOG_TRACE("%s", IndexFactory::GetInfo(metadata, comparatorType).c_str());
215223
#endif
216-
return (index);
224+
225+
return index;
217226
}
218227

219228
Index *IndexFactory::GetSkipListIntsKeyIndex(IndexMetadata *metadata) {
@@ -271,7 +280,8 @@ Index *IndexFactory::GetSkipListIntsKeyIndex(IndexMetadata *metadata) {
271280
#ifdef LOG_TRACE_ENABLED
272281
LOG_TRACE("%s", IndexFactory::GetInfo(metadata, comparatorType).c_str());
273282
#endif
274-
return (index);
283+
284+
return index;
275285
}
276286

277287
Index *IndexFactory::GetSkipListGenericKeyIndex(IndexMetadata *metadata) {
@@ -339,18 +349,19 @@ Index *IndexFactory::GetSkipListGenericKeyIndex(IndexMetadata *metadata) {
339349
#ifdef LOG_TRACE_ENABLED
340350
LOG_TRACE("%s", IndexFactory::GetInfo(metadata, comparatorType).c_str());
341351
#endif
342-
return (index);
352+
353+
return index;
343354
}
344355

345356
std::string IndexFactory::GetInfo(IndexMetadata *metadata,
346-
std::string comparatorType) {
357+
const std::string &comparator_type) {
347358
std::ostringstream os;
348359
os << "Index '" << metadata->GetName() << "' => "
349-
<< IndexTypeToString(metadata->GetIndexType()) << "::" << comparatorType
360+
<< IndexTypeToString(metadata->GetIndexType()) << "::" << comparator_type
350361
<< "(";
351362
bool first = true;
352363
for (auto column : metadata->key_schema->GetColumns()) {
353-
if (first == false) os << ", ";
364+
if (!first) os << ", ";
354365
os << column.GetName();
355366
first = false;
356367
}

0 commit comments

Comments
 (0)