mirror of https://gitee.com/bigwinds/arangodb
micro optimizations
This commit is contained in:
parent
e2d0f4342f
commit
e468a51ad2
|
@ -62,34 +62,11 @@ Index::Index(TRI_idx_iid_t iid, arangodb::LogicalCollection* collection,
|
|||
slice, "unique", false)),
|
||||
_sparse(arangodb::basics::VelocyPackHelper::getBooleanValue(
|
||||
slice, "sparse", false)),
|
||||
_selectivityEstimate(0.0) {
|
||||
_selectivityEstimate(arangodb::basics::VelocyPackHelper::getNumericValue<double>(
|
||||
slice, "selectivityEstimate", 0.0)) {
|
||||
|
||||
VPackSlice const fields = slice.get("fields");
|
||||
|
||||
if (fields.isArray()) {
|
||||
size_t const n = static_cast<size_t>(fields.length());
|
||||
_fields.reserve(n);
|
||||
|
||||
for (auto const& name : VPackArrayIterator(fields)) {
|
||||
if (!name.isString()) {
|
||||
LOG(ERR) << "ignoring index " << iid
|
||||
<< ", 'fields' must be an array of attribute paths";
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
||||
"invalid index description");
|
||||
}
|
||||
|
||||
std::vector<arangodb::basics::AttributeName> parsedAttributes;
|
||||
TRI_ParseAttributeString(name.copyString(), parsedAttributes, allowExpansion);
|
||||
_fields.emplace_back(std::move(parsedAttributes));
|
||||
}
|
||||
} else if (!fields.isNone()) {
|
||||
LOG(ERR) << "ignoring index " << iid << ", 'fields' must be an array";
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
||||
"invalid index description");
|
||||
}
|
||||
// fields is NOT mandatory for all indexes.
|
||||
// But if it is contained it has to be an array.
|
||||
// Every index has to validate in it's own constructor if _fields
|
||||
// is correct.
|
||||
setFields(fields);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -107,11 +84,19 @@ Index::Index(VPackSlice const& slice)
|
|||
slice, "unique", false)),
|
||||
_sparse(arangodb::basics::VelocyPackHelper::getBooleanValue(
|
||||
slice, "sparse", false)),
|
||||
_selectivityEstimate(0.0) {
|
||||
VPackSlice const fields = slice.get("fields");
|
||||
_selectivityEstimate(arangodb::basics::VelocyPackHelper::getNumericValue<double>(
|
||||
slice, "selectivityEstimate", 0.0)) {
|
||||
|
||||
VPackSlice const fields = slice.get("fields");
|
||||
setFields(fields);
|
||||
}
|
||||
|
||||
Index::~Index() {}
|
||||
|
||||
/// @brief set fields from slice
|
||||
void Index::setFields(VPackSlice const& fields) {
|
||||
if (!fields.isArray()) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_ATTRIBUTE_PARSER_FAILED,
|
||||
"invalid index description");
|
||||
}
|
||||
|
||||
|
@ -120,7 +105,7 @@ Index::Index(VPackSlice const& slice)
|
|||
|
||||
for (auto const& name : VPackArrayIterator(fields)) {
|
||||
if (!name.isString()) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_INTERNAL,
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_ATTRIBUTE_PARSER_FAILED,
|
||||
"invalid index description");
|
||||
}
|
||||
|
||||
|
@ -128,18 +113,27 @@ Index::Index(VPackSlice const& slice)
|
|||
TRI_ParseAttributeString(name.copyString(), parsedAttributes, true);
|
||||
_fields.emplace_back(std::move(parsedAttributes));
|
||||
}
|
||||
|
||||
_selectivityEstimate =
|
||||
arangodb::basics::VelocyPackHelper::getNumericValue<double>(
|
||||
slice, "selectivityEstimate", 0.0);
|
||||
}
|
||||
|
||||
Index::~Index() {}
|
||||
/// @brief validate fields from slice
|
||||
void Index::validateFields(VPackSlice const& fields) {
|
||||
if (!fields.isArray()) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_ATTRIBUTE_PARSER_FAILED,
|
||||
"invalid index description");
|
||||
}
|
||||
|
||||
for (auto const& name : VPackArrayIterator(fields)) {
|
||||
if (!name.isString()) {
|
||||
THROW_ARANGO_EXCEPTION_MESSAGE(TRI_ERROR_ARANGO_ATTRIBUTE_PARSER_FAILED,
|
||||
"invalid index description");
|
||||
}
|
||||
|
||||
std::vector<arangodb::basics::AttributeName> parsedAttributes;
|
||||
TRI_ParseAttributeString(name.copyString(), parsedAttributes, true);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the index type based on a type name
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Index::IndexType Index::type(char const* type) {
|
||||
if (::strcmp(type, "primary") == 0) {
|
||||
return TRI_IDX_TYPE_PRIMARY_INDEX;
|
||||
|
|
|
@ -166,16 +166,10 @@ class Index {
|
|||
};
|
||||
|
||||
public:
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the index id
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline TRI_idx_iid_t id() const { return _iid; }
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief return the index fields
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline std::vector<std::vector<arangodb::basics::AttributeName>> const&
|
||||
fields() const {
|
||||
return _fields;
|
||||
|
@ -260,6 +254,9 @@ class Index {
|
|||
|
||||
/// @brief whether or not the index is unique
|
||||
inline bool unique() const { return _unique; }
|
||||
|
||||
/// @brief validate fields from slice
|
||||
static void validateFields(VPackSlice const&);
|
||||
|
||||
/// @brief return the name of the index
|
||||
char const* typeName() const { return typeName(type()); }
|
||||
|
@ -371,6 +368,10 @@ class Index {
|
|||
|
||||
virtual void expandInSearchValues(arangodb::velocypack::Slice const,
|
||||
arangodb::velocypack::Builder&) const;
|
||||
|
||||
private:
|
||||
/// @brief set fields from slice
|
||||
void setFields(VPackSlice const&);
|
||||
|
||||
protected:
|
||||
TRI_idx_iid_t const _iid;
|
||||
|
|
|
@ -589,11 +589,13 @@ static void EnsureIndex(v8::FunctionCallbackInfo<v8::Value> const& args,
|
|||
|
||||
// check if there is an attempt to create a unique index on non-shard keys
|
||||
if (create) {
|
||||
VPackSlice flds = slice.get("fields");
|
||||
Index::validateFields(flds);
|
||||
|
||||
VPackSlice v = slice.get("unique");
|
||||
|
||||
if (v.isBoolean() && v.getBoolean()) {
|
||||
// unique index, now check if fields and shard keys match
|
||||
VPackSlice flds = slice.get("fields");
|
||||
if (flds.isArray() && c->numberOfShards() > 1) {
|
||||
std::vector<std::string> const& shardKeys = c->shardKeys();
|
||||
size_t n = static_cast<size_t>(flds.length());
|
||||
|
|
|
@ -404,28 +404,29 @@ DropCollectionDitch* Ditches::createDropCollectionDitch(
|
|||
/// @brief inserts the ditch into the linked list of ditches
|
||||
void Ditches::link(Ditch* ditch) {
|
||||
TRI_ASSERT(ditch != nullptr);
|
||||
|
||||
ditch->_next = nullptr;
|
||||
ditch->_prev = nullptr;
|
||||
|
||||
bool const isDocumentDitch = (ditch->type() == Ditch::TRI_DITCH_DOCUMENT);
|
||||
|
||||
MUTEX_LOCKER(mutexLocker, _lock); // FIX_MUTEX
|
||||
|
||||
// empty list
|
||||
if (_end == nullptr) {
|
||||
ditch->_next = nullptr;
|
||||
ditch->_prev = nullptr;
|
||||
|
||||
_begin = ditch;
|
||||
_end = ditch;
|
||||
}
|
||||
|
||||
// add to the end
|
||||
else {
|
||||
ditch->_next = nullptr;
|
||||
ditch->_prev = _end;
|
||||
|
||||
_end->_next = ditch;
|
||||
_end = ditch;
|
||||
}
|
||||
|
||||
if (ditch->type() == Ditch::TRI_DITCH_DOCUMENT) {
|
||||
if (isDocumentDitch) {
|
||||
// increase counter
|
||||
++_numDocumentDitches;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue