This repository was archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathTupleStorageSubBlock.cpp
More file actions
110 lines (93 loc) · 2.99 KB
/
TupleStorageSubBlock.cpp
File metadata and controls
110 lines (93 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* Copyright 2011-2015 Quickstep Technologies LLC.
* Copyright 2015 Pivotal Software, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
#include "storage/TupleStorageSubBlock.hpp"
#ifdef QUICKSTEP_DEBUG
#include <cassert>
#endif
#include "storage/TupleIdSequence.hpp"
#include "storage/ValueAccessor.hpp"
#include "utility/Macros.hpp"
#ifdef QUICKSTEP_DEBUG
#include "catalog/CatalogAttribute.hpp"
#include "catalog/CatalogRelationSchema.hpp"
#include "types/Type.hpp"
#include "types/TypedValue.hpp"
#include "types/containers/Tuple.hpp"
#endif
namespace quickstep {
tuple_id TupleStorageSubBlock::numTuples() const {
if (isEmpty()) {
return 0;
} else if (isPacked()) {
return getMaxTupleID() + 1;
} else {
// WARNING: This branch is O(N). Subclasses should override wherever possible.
tuple_id count = 0;
for (tuple_id tid = 0; tid <= getMaxTupleID(); ++tid) {
if (hasTupleWithID(tid)) {
++count;
}
}
// Should have at least one tuple, otherwise isEmpty() would have been true.
DEBUG_ASSERT(count > 0);
return count;
}
}
TupleIdSequence* TupleStorageSubBlock::getExistenceMap() const {
const tuple_id max_tid = getMaxTupleID();
TupleIdSequence *existing_tuples = new TupleIdSequence(max_tid + 1);
if (isPacked()) {
existing_tuples->setRange(0, max_tid + 1, true);
} else {
for (tuple_id tid = 0; tid <= max_tid; ++tid) {
if (hasTupleWithID(tid)) {
existing_tuples->set(tid, true);
}
}
}
return existing_tuples;
}
OrderedTupleIdSequence* TupleStorageSubBlock::getExistenceList() const {
const tuple_id max_tid = getMaxTupleID();
OrderedTupleIdSequence *existence_list = new OrderedTupleIdSequence();
existence_list->reserve(numTuples());
if (isPacked()) {
for (tuple_id tid = 0; tid <= max_tid; ++tid) {
existence_list->emplace_back(tid);
}
} else {
for (tuple_id tid = 0; tid <= max_tid; ++tid) {
if (hasTupleWithID(tid)) {
existence_list->emplace_back(tid);
}
}
}
return existence_list;
}
void TupleStorageSubBlock::paranoidInsertTypeCheck(const Tuple &tuple) {
#ifdef QUICKSTEP_DEBUG
assert(relation_.size() == tuple.size());
Tuple::const_iterator value_it = tuple.begin();
CatalogRelationSchema::const_iterator attr_it = relation_.begin();
while (value_it != tuple.end()) {
assert(value_it->isPlausibleInstanceOf(attr_it->getType().getSignature()));
++value_it;
++attr_it;
}
#endif
}
} // namespace quickstep