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

Commit cf631f4

Browse files
Address review comments + minor clean-up in the layout.h API
1 parent a1a7280 commit cf631f4

19 files changed

+146
-99
lines changed

src/catalog/catalog.cpp

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ void Catalog::BootstrapSystemCatalogs(storage::Database *database,
162162
system_catalogs->GetSchemaCatalog()->InsertSchema(
163163
CATALOG_SCHEMA_OID, CATALOG_SCHEMA_NAME, pool_.get(), txn);
164164
system_catalogs->GetSchemaCatalog()->InsertSchema(
165-
DEFUALT_SCHEMA_OID, DEFAULT_SCHEMA_NAME, pool_.get(), txn);
165+
DEFAULT_SCHEMA_OID, DEFAULT_SCHEMA_NAME, pool_.get(), txn);
166166

167167
// Insert catalog tables into pg_table
168168
// pg_database record is shared across different databases
@@ -561,15 +561,6 @@ ResultType Catalog::CreateIndex(
561561
return ResultType::SUCCESS;
562562
}
563563

564-
/*
565-
* @brief create a new layout for a table
566-
* @param database_oid database to which the table belongs to
567-
* @param table_oid table to which the layout has to be added
568-
* @param column_map column_map of the new layout to be created
569-
* @param txn TransactionContext
570-
* @return shared_ptr shared_ptr to the newly created layout in case of
571-
* success. nullptr in case of failure.
572-
*/
573564
std::shared_ptr<const storage::Layout> Catalog::CreateLayout(
574565
oid_t database_oid, oid_t table_oid, const column_map_type &column_map,
575566
concurrency::TransactionContext *txn) {
@@ -594,16 +585,6 @@ std::shared_ptr<const storage::Layout> Catalog::CreateLayout(
594585
return new_layout;
595586
}
596587

597-
/*
598-
* @brief create a new layout for a table and make it the deafult if
599-
* if the creating is successsful.
600-
* @param database_oid database to which the table belongs to
601-
* @param table_oid table to which the layout has to be added
602-
* @param column_map column_map of the new layout to be created
603-
* @param txn TransactionContext
604-
* @return shared_ptr shared_ptr to the newly created layout in case of
605-
* success. nullptr in case of failure.
606-
*/
607588
std::shared_ptr<const storage::Layout> Catalog::CreateDefaultLayout(
608589
oid_t database_oid, oid_t table_oid, const column_map_type &column_map,
609590
concurrency::TransactionContext *txn) {
@@ -830,14 +811,6 @@ ResultType Catalog::DropIndex(oid_t database_oid, oid_t index_oid,
830811
return ResultType::SUCCESS;
831812
}
832813

833-
/*@brief Drop layout
834-
* tile_groups
835-
* @param database_oid the database to which the table belongs
836-
* @param table_oid the table to which the layout belongs
837-
* @param layout_oid the layout to be dropped
838-
* @param txn TransactionContext
839-
* @return TransactionContext ResultType(SUCCESS or FAILURE)
840-
*/
841814
ResultType Catalog::DropLayout(oid_t database_oid, oid_t table_oid,
842815
oid_t layout_oid,
843816
concurrency::TransactionContext *txn) {

src/catalog/table_catalog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ TableCatalog::TableCatalog(
338338
bool TableCatalogObject::InsertLayout(
339339
std::shared_ptr<const storage::Layout> layout) {
340340
// Invalid object
341-
if (layout == nullptr) {
341+
if (!layout || (layout->GetOid() == INVALID_OID)) {
342342
return false;
343343
}
344344

src/codegen/proxy/runtime_functions_proxy.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "codegen/proxy/runtime_functions_proxy.h"
14+
1415
#include "codegen/proxy/data_table_proxy.h"
1516
#include "codegen/proxy/tile_group_proxy.h"
1617
#include "codegen/proxy/zone_map_proxy.h"
@@ -24,8 +25,6 @@ DEFINE_TYPE(ColumnLayoutInfo, "peloton::ColumnLayoutInfo",
2425
DEFINE_TYPE(AbstractExpression, "peloton::expression::AbstractExpression",
2526
MEMBER(opaque));
2627

27-
DEFINE_TYPE(Schema, "peloton::catalog::Schema", MEMBER(opaque));
28-
2928
DEFINE_METHOD(peloton::codegen, RuntimeFunctions, HashCrc64);
3029
DEFINE_METHOD(peloton::codegen, RuntimeFunctions, GetTileGroup);
3130
DEFINE_METHOD(peloton::codegen, RuntimeFunctions, GetTileGroupLayout);

src/codegen/runtime_functions.cpp

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -102,38 +102,38 @@ void RuntimeFunctions::FillPredicateArray(
102102
// to skip over to find successive values of the column.
103103
//===----------------------------------------------------------------------===//
104104
void RuntimeFunctions::GetTileGroupLayout(const storage::TileGroup *tile_group,
105-
const catalog::Schema *schema,
106105
ColumnLayoutInfo *infos,
107-
uint32_t num_cols) {
106+
UNUSED_ATTRIBUTE uint32_t num_cols) {
108107
const auto &layout = tile_group->GetLayout();
109-
// For LayoutType::ROW, the tile group contains a single tile
110-
// and all the columns are in the same order as the table schema.
111-
if (layout.IsRowStore()) {
112-
auto tuple_location = tile_group->GetTile(0)->GetTupleLocation(0);
113-
auto stride = schema->GetLength();
114-
for (uint32_t col_idx = 0; col_idx < num_cols; col_idx++) {
115-
infos[col_idx].column = tuple_location + schema->GetOffset(col_idx);
116-
infos[col_idx].stride = stride;
117-
infos[col_idx].is_columnar = false;
118-
}
119-
return;
120-
}
121-
for (uint32_t col_idx = 0; col_idx < num_cols; col_idx++) {
122-
// Map the current column to a tile and a column offset in the tile
123-
oid_t tile_offset, tile_column_offset;
124-
layout.LocateTileAndColumn(col_idx, tile_offset, tile_column_offset);
108+
UNUSED_ATTRIBUTE oid_t last_col_idx = INVALID_OID;
125109

126-
// Now grab the column information
127-
auto *tile = tile_group->GetTile(tile_offset);
128-
auto *tile_schema = tile->GetSchema();
129-
infos[col_idx].column =
130-
tile->GetTupleLocation(0) + tile_schema->GetOffset(tile_column_offset);
131-
infos[col_idx].stride = tile_schema->GetLength();
132-
infos[col_idx].is_columnar = tile_schema->GetColumnCount() == 1;
133-
LOG_TRACE("Col [%u] start: %p, stride: %u, columnar: %s", col_idx,
134-
infos[col_idx].column, infos[col_idx].stride,
135-
infos[col_idx].is_columnar ? "true" : "false");
110+
auto tile_map = layout.GetTileMap();
111+
// Find the mapping for each tile in the layout.
112+
for (auto tile_entry : tile_map) {
113+
// Get the tile schema.
114+
auto tile_idx = tile_entry.first;
115+
auto *tile = tile_group->GetTile(tile_idx);
116+
auto tile_schema = tile->GetSchema();
117+
// Map the current column to a tile and a column offset in the tile.
118+
for (auto column_entry : tile_entry.second) {
119+
// Now grab the column information
120+
oid_t col_idx = column_entry.first;
121+
oid_t tile_col_offset = column_entry.second;
122+
// Ensure that the col_idx is within the num_cols range
123+
PELOTON_ASSERT(col_idx < num_cols);
124+
infos[col_idx].column =
125+
tile->GetTupleLocation(0) + tile_schema->GetOffset(tile_col_offset);
126+
infos[col_idx].stride = tile_schema->GetLength();
127+
infos[col_idx].is_columnar = tile_schema->GetColumnCount() == 1;
128+
last_col_idx = col_idx;
129+
LOG_TRACE("Col [%u] start: %p, stride: %u, columnar: %s", col_idx,
130+
infos[col_idx].column, infos[col_idx].stride,
131+
infos[col_idx].is_columnar ? "true" : "false");
132+
}
136133
}
134+
// Ensure that ColumnLayoutInfo for each column has been populated.
135+
PELOTON_ASSERT((last_col_idx != INVALID_OID) &&
136+
(last_col_idx == (num_cols - 1)));
137137
}
138138

139139
void RuntimeFunctions::ThrowDivideByZeroException() {

src/codegen/tile_group.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,12 @@ llvm::Value *TileGroup::GetTileGroupId(CodeGen &codegen,
8888
std::vector<TileGroup::ColumnLayout> TileGroup::GetColumnLayouts(
8989
CodeGen &codegen, llvm::Value *tile_group_ptr,
9090
llvm::Value *column_layout_infos) const {
91-
llvm::Value *schema_ptr =
92-
codegen->CreateIntToPtr(codegen.Const64((int64_t)&schema_),
93-
SchemaProxy::GetType(codegen)->getPointerTo());
9491

9592
// Call RuntimeFunctions::GetTileGroupLayout()
9693
uint32_t num_cols = schema_.GetColumnCount();
97-
codegen.Call(RuntimeFunctionsProxy::GetTileGroupLayout,
98-
{tile_group_ptr, schema_ptr, column_layout_infos,
99-
codegen.Const32(num_cols)});
94+
codegen.Call(
95+
RuntimeFunctionsProxy::GetTileGroupLayout,
96+
{tile_group_ptr, column_layout_infos, codegen.Const32(num_cols)});
10097

10198
// Collect <start, stride, is_columnar> triplets of all columns
10299
std::vector<TileGroup::ColumnLayout> layouts;

src/include/catalog/catalog.h

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,29 @@ class Catalog {
120120
concurrency::TransactionContext *txn,
121121
bool is_catalog = false);
122122

123-
// Create a new layout
123+
/**
124+
* @brief create a new layout for a table
125+
* @param database_oid database to which the table belongs to
126+
* @param table_oid table to which the layout has to be added
127+
* @param column_map column_map of the new layout to be created
128+
* @param txn TransactionContext
129+
* @return shared_ptr shared_ptr to the newly created layout in case of
130+
* success. nullptr in case of failure.
131+
*/
124132
std::shared_ptr<const storage::Layout> CreateLayout(
125133
oid_t database_oid, oid_t table_oid, const column_map_type &column_map,
126134
concurrency::TransactionContext *txn);
127135

128-
// Create a new layout and set it as the default for the table
136+
/**
137+
* @brief create a new layout for a table and make it the default if
138+
* if the creating is successsful.
139+
* @param database_oid database to which the table belongs to
140+
* @param table_oid table to which the layout has to be added
141+
* @param column_map column_map of the new layout to be created
142+
* @param txn TransactionContext
143+
* @return shared_ptr shared_ptr to the newly created layout in case of
144+
* success. nullptr in case of failure.
145+
*/
129146
std::shared_ptr<const storage::Layout> CreateDefaultLayout(
130147
oid_t database_oid, oid_t table_oid, const column_map_type &column_map,
131148
concurrency::TransactionContext *txn);
@@ -158,7 +175,14 @@ class Catalog {
158175
ResultType DropIndex(oid_t database_oid, oid_t index_oid,
159176
concurrency::TransactionContext *txn);
160177

161-
// Delete a layout using its database_oid, table_oid and layout_oid
178+
/** @brief Drop layout
179+
* tile_groups
180+
* @param database_oid the database to which the table belongs
181+
* @param table_oid the table to which the layout belongs
182+
* @param layout_oid the layout to be dropped
183+
* @param txn TransactionContext
184+
* @return ResultType(SUCCESS or FAILURE)
185+
*/
162186
ResultType DropLayout(oid_t database_oid, oid_t table_oid, oid_t layout_oid,
163187
concurrency::TransactionContext *txn);
164188
//===--------------------------------------------------------------------===//

src/include/catalog/catalog_defaults.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ namespace catalog {
5353
// Reserved schema oid
5454
// "public" for default schema, and "pg_catalog" schema for catalog tables
5555
#define CATALOG_SCHEMA_OID (0 | SCHEMA_OID_MASK)
56-
#define DEFUALT_SCHEMA_OID (1 | SCHEMA_OID_MASK)
56+
#define DEFAULT_SCHEMA_OID (1 | SCHEMA_OID_MASK)
5757
#define CATALOG_SCHEMA_NAME "pg_catalog"
5858
#define DEFAULT_SCHEMA_NAME "public"
5959

src/include/catalog/layout_catalog.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ namespace catalog {
3939

4040
class LayoutCatalog : public AbstractCatalog {
4141
public:
42-
// Global Singleton, only the first call requires passing parameters.
43-
static LayoutCatalog *GetInstance(
44-
storage::Database *pg_catalog = nullptr,
45-
type::AbstractPool *pool = nullptr,
46-
concurrency::TransactionContext *txn = nullptr);
4742

4843
LayoutCatalog(storage::Database *pg_catalog, type::AbstractPool *pool,
4944
concurrency::TransactionContext *txn);

src/include/codegen/proxy/runtime_functions_proxy.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ PROXY(RuntimeFunctions) {
5151

5252
TYPE_BUILDER(ColumnLayoutInfo, codegen::RuntimeFunctions::ColumnLayoutInfo);
5353
TYPE_BUILDER(AbstractExpression, expression::AbstractExpression);
54-
TYPE_BUILDER(Schema, catalog::Schema);
5554

5655
} // namespace codegen
5756
} // namespace peloton

src/include/codegen/runtime_functions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ class RuntimeFunctions {
7070

7171
// Get the column configuration for every column in the tile group
7272
static void GetTileGroupLayout(const storage::TileGroup *tile_group,
73-
const catalog::Schema *schema,
7473
ColumnLayoutInfo *infos, uint32_t num_cols);
7574

7675
static void ThrowDivideByZeroException();

0 commit comments

Comments
 (0)