Skip to content

Commit 7a39035

Browse files
committed
Update for V5.8
1 parent e655864 commit 7a39035

File tree

88 files changed

+11123
-2649
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+11123
-2649
lines changed

server/base_container.cpp

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,74 @@ void BaseContainer::searchColumnIdIndex(TransactionContext &txn,
557557
}
558558
}
559559

560+
int64_t BaseContainer::estimateIndexSearchSize(
561+
TransactionContext &txn, BtreeMap::SearchContext &sc) {
562+
const util::Vector<ColumnId> &columnIds = sc.getColumnIds();
563+
564+
uint64_t estimationSize;
565+
if (getContainerType() == TIME_SERIES_CONTAINER &&
566+
columnIds.size() == 1 && columnIds.front() == 0) {
567+
estimateRowIdIndexSearchSize(txn, sc, estimationSize);
568+
}
569+
else {
570+
if (!estimateColumnIdIndexSearchSize(txn, sc, estimationSize)) {
571+
return -1;
572+
}
573+
}
574+
575+
return static_cast<int64_t>(std::min(
576+
estimationSize,
577+
static_cast<uint64_t>(std::numeric_limits<int64_t>::max())));
578+
}
579+
580+
void BaseContainer::estimateRowIdIndexSearchSize(
581+
TransactionContext &txn, BtreeMap::SearchContext &sc,
582+
uint64_t &estimationSize) {
583+
estimationSize = 0;
584+
585+
const util::Vector<ColumnId> &columnIds = sc.getColumnIds();
586+
assert(columnIds.size() == 1 && columnIds.front() == 0);
587+
static_cast<void>(columnIds);
588+
589+
StackAllocAutoPtr<BtreeMap> rowIdMap(
590+
txn.getDefaultAllocator(), getRowIdMap(txn));
591+
estimationSize = toEstimationSize(rowIdMap.get()->estimate(txn, sc));
592+
}
593+
594+
bool BaseContainer::estimateColumnIdIndexSearchSize(
595+
TransactionContext &txn, BtreeMap::SearchContext &sc,
596+
uint64_t &estimationSize) {
597+
estimationSize = 0;
598+
599+
const MapType mapType = MAP_TYPE_BTREE;
600+
const bool withUncommitted = false;
601+
602+
const util::Vector<ColumnId> &columnIds = sc.getColumnIds();
603+
IndexData &indexData = sc.prepareIndexData(txn.getDefaultAllocator());
604+
if (!getIndexData(txn, columnIds, mapType, withUncommitted, indexData)) {
605+
return false;
606+
}
607+
608+
ValueMap valueMap(txn, this, indexData);
609+
estimationSize = toEstimationSize(valueMap.estimate<BtreeMap>(txn, sc));
610+
return true;
611+
}
612+
613+
uint64_t BaseContainer::toEstimationSize(uint64_t base) {
614+
if (base <= 0) {
615+
return 0;
616+
}
617+
618+
const uint64_t max = std::numeric_limits<uint64_t>::max();
619+
const uint64_t total = getRowNum();
620+
621+
const double rate = static_cast<double>(base) / static_cast<double>(max);
622+
const double rawSize = rate * static_cast<double>(total);
623+
624+
const uint64_t size = static_cast<uint64_t>(rawSize);
625+
return std::min(std::max<uint64_t>(size, 1), total);
626+
}
627+
560628
/*!
561629
@brief Get list of Row in Message format
562630
*/
@@ -1984,6 +2052,8 @@ void BaseContainer::resolveExclusiveStatus(TransactionContext& txn) {
19842052
return;
19852053
}
19862054

2055+
util::StackAllocator::Scope scope(txn.getDefaultAllocator());
2056+
19872057
BtreeMap::SearchContext sc (txn.getDefaultAllocator(), UNDEF_COLUMNID);
19882058
const bool checkOnly = true;
19892059
util::XArray<OId> dummyList(txn.getDefaultAllocator());
@@ -2614,6 +2684,13 @@ int32_t BaseContainer::ValueMap::search<BtreeMap>(TransactionContext &txn,
26142684
return 0;
26152685
}
26162686

2687+
template <typename T>
2688+
uint64_t BaseContainer::ValueMap::estimate(
2689+
TransactionContext &txn, typename T::SearchContext &sc) {
2690+
const bool forNull = false;
2691+
T *map = static_cast<T*>(getValueMap(txn, forNull));
2692+
return map->estimate(txn, sc);
2693+
}
26172694

26182695
/*!
26192696
@brief Check if Container has data of uncommited transaction

server/base_container.h

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,20 @@ class BaseContainer : public BaseObject {
123123
MapType getMapType() {
124124
return indexData_.mapType_;
125125
}
126+
127+
template <typename T>
128+
int32_t search(
129+
TransactionContext &txn, typename T::SearchContext &sc,
130+
util::XArray<OId> &oIdList, OutputOrder outputOrder);
131+
126132
template <typename T>
127-
int32_t search(TransactionContext &txn, typename T::SearchContext &sc,
128-
util::XArray<OId> &oIdList, OutputOrder outputOrder);
133+
uint64_t estimate(
134+
TransactionContext &txn, typename T::SearchContext &sc);
135+
129136
TreeFuncInfo *getFuncInfo(TransactionContext &txn) {
130137
return getValueMap(txn, false)->getFuncInfo();
131138
}
139+
132140
private:
133141
BaseContainer *container_;
134142
IndexAutoPtr valueMap_;
@@ -395,6 +403,16 @@ class BaseContainer : public BaseObject {
395403
BtreeMap::SearchContext &sc, util::XArray<OId> &normalRowList,
396404
util::XArray<OId> &mvccRowList);
397405

406+
int64_t estimateIndexSearchSize(
407+
TransactionContext &txn, BtreeMap::SearchContext &sc);
408+
void estimateRowIdIndexSearchSize(
409+
TransactionContext &txn, BtreeMap::SearchContext &sc,
410+
uint64_t &estimationSize);
411+
bool estimateColumnIdIndexSearchSize(
412+
TransactionContext &txn, BtreeMap::SearchContext &sc,
413+
uint64_t &estimationSize);
414+
uint64_t toEstimationSize(uint64_t base);
415+
398416
void getRowList(TransactionContext &txn, util::XArray<OId> &oIdList,
399417
ResultSize limit, ResultSize &resultNum,
400418
MessageRowStore *messageRowStore, bool isWithRowId,

server/btree_map.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ struct BtreeMap::MapKeyTraits<CompositeInfoObject136> {
9595
#if !GS_BTREE_MAP_DEFINE_SWITCHER_ONLY
9696
int32_t BtreeMap::compositeInfoCmp(TransactionContext &txn, ObjectManagerV4 &objectManager, AllocateStrategy &strategy,
9797
const CompositeInfoObject *e1, const CompositeInfoObject *e2, BaseIndex::Setting &setting) {
98+
99+
util::StackAllocator::Scope scope(txn.getDefaultAllocator());
100+
98101
int32_t ret = 0;
99102
TreeFuncInfo *funcInfo = setting.getFuncInfo();
100103
assert(funcInfo != NULL);
@@ -133,6 +136,9 @@ int32_t BtreeMap::compositeInfoCmp(TransactionContext &txn, ObjectManagerV4 &obj
133136
template <>
134137
bool BtreeMap::compositeInfoMatch(TransactionContext &txn, ObjectManagerV4 &objectManager,
135138
const CompositeInfoObject *e, BaseIndex::Setting &setting) {
139+
140+
util::StackAllocator::Scope scope(txn.getDefaultAllocator());
141+
136142
bool isMatch = true;
137143
TreeFuncInfo *funcInfo = setting.getFuncInfo();
138144
VariableArrayCursor *cursor = NULL;

server/btree_map.h

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,8 @@ class BtreeMap : public BaseIndex {
535535
return rootNode.getTailNodeOId();
536536
}
537537

538+
uint64_t estimate(TransactionContext &txn, SearchContext &sc);
539+
538540
inline bool isEmpty() const {
539541
BNode<char, char> rootNode(this, *const_cast<AllocateStrategy*>(&allocateStrategy_));
540542
return rootNode.numkeyValues() == 0;
@@ -619,6 +621,39 @@ class BtreeMap : public BaseIndex {
619621
}
620622
};
621623

624+
template <typename P, typename K, typename V, CompareComponent C>
625+
class BoundaryCmpFunctor {
626+
public:
627+
BoundaryCmpFunctor(bool lower, bool inclusive) :
628+
eqRet_(resolveEqResult(lower, inclusive)) {
629+
}
630+
631+
int32_t operator()(
632+
TransactionContext &txn, ObjectManagerV4 &objectManager,
633+
AllocateStrategy &strategy, const KeyValue<P, V> &e1,
634+
const KeyValue<K, V> &e2, Setting &setting) const {
635+
CmpFunctor<P, K, V, C> base;
636+
const int32_t baseRet =
637+
base(txn, objectManager, strategy, e1, e2, setting);
638+
if (baseRet == 0) {
639+
return eqRet_;
640+
}
641+
return baseRet;
642+
}
643+
644+
private:
645+
static int32_t resolveEqResult(bool lower, bool inclusive) {
646+
if (inclusive) {
647+
return 0;
648+
}
649+
else {
650+
return (lower ? 1 : -1);
651+
}
652+
}
653+
654+
int32_t eqRet_;
655+
};
656+
622657
/*!
623658
@brief Btree Node Header format
624659
*/
@@ -1232,6 +1267,10 @@ class BtreeMap : public BaseIndex {
12321267
};
12331268

12341269
struct SearchBulkFunc;
1270+
struct EstimateFunc;
1271+
1272+
typedef std::pair<int32_t, int32_t> LocationEntry;
1273+
typedef util::Vector<LocationEntry> LocationPath;
12351274

12361275
template<typename Action>
12371276
void switchToBasicType(ColumnType type, Action &action);
@@ -1912,6 +1951,11 @@ class BtreeMap : public BaseIndex {
19121951
TransactionContext &txn, SearchContext &sc, util::XArray<R> &idList,
19131952
Setting &setting, BNode<K, V> &node, int32_t &loc);
19141953

1954+
template <typename P, typename K, typename V, typename C>
1955+
bool findNodeCustom(
1956+
TransactionContext &txn, KeyValue<P, V> &val, BNode<K, V> &node,
1957+
int32_t &loc, C &cmp, Setting &setting);
1958+
19151959
template <typename P, typename K, typename V, typename R, CompareComponent C>
19161960
bool findGreaterNext(
19171961
TransactionContext &txn, KeyValue<P, V> &keyValue,
@@ -1935,6 +1979,41 @@ class BtreeMap : public BaseIndex {
19351979
TransactionContext &txn, KeyValue<P, V> &val, BNode<K, V> &node,
19361980
int32_t &loc, CmpFunctor<P, K, V, C> &cmp, Setting &setting);
19371981

1982+
template<typename P, typename K, typename V, CompareComponent C>
1983+
uint64_t estimateAt(TransactionContext &txn, SearchContext &sc);
1984+
1985+
template<typename K, typename V>
1986+
uint64_t estimatePathRange(
1987+
TransactionContext &txn, const LocationPath &beginPath,
1988+
const LocationPath &endPath);
1989+
1990+
uint64_t estimatePathRangeSub(
1991+
const LocationPath &beginPath, const LocationPath &endPath);
1992+
1993+
static uint64_t mergePathRangeSize(uint64_t size1, uint64_t size2);
1994+
1995+
template<typename P, typename K, typename V, CompareComponent C>
1996+
void findLocationPath(
1997+
TransactionContext &txn, KeyValue<P, V> &keyValue,
1998+
bool inclusive, bool less, Setting &setting, LocationPath &path);
1999+
2000+
template<typename K, typename V>
2001+
void getHeadLocationPath(
2002+
TransactionContext &txn, LocationPath &path);
2003+
template<typename K, typename V>
2004+
void getTailLocationPath(
2005+
TransactionContext &txn, LocationPath &path);
2006+
2007+
template<typename K, typename V>
2008+
bool findMiddleLocationPath(
2009+
TransactionContext &txn, const LocationPath &beginPath,
2010+
const LocationPath &endPath, LocationPath &path);
2011+
2012+
template<typename K, typename V>
2013+
void nodeToLocationPath(
2014+
TransactionContext &txn, BNode<K, V> &node, int32_t &loc,
2015+
LocationPath &path);
2016+
19382017
static void errorInvalidSearchCondition();
19392018
};
19402019

0 commit comments

Comments
 (0)