diff options
author | Jason Rassi <rassi@10gen.com> | 2015-05-07 10:49:55 -0400 |
---|---|---|
committer | Jason Rassi <rassi@10gen.com> | 2015-05-07 11:13:28 -0400 |
commit | a3add38aaf5385a49d5e8a72ee05c6bbe0e13611 (patch) | |
tree | 1dea0b4b8332e67326773d7f14966aa1afee26b0 /src/mongo/db/query/plan_cache_indexability.cpp | |
parent | fd777917d262d759fa3fa83998cd67ef70b8b8f9 (diff) | |
download | mongo-a3add38aaf5385a49d5e8a72ee05c6bbe0e13611.tar.gz |
SERVER-17659 Add PlanCacheIndexabilityState
Encapsulates functionality to be used by PlanCache, for deciding how
to cache queries with predicates over elements in partial index key
patterns.
Diffstat (limited to 'src/mongo/db/query/plan_cache_indexability.cpp')
-rw-r--r-- | src/mongo/db/query/plan_cache_indexability.cpp | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/mongo/db/query/plan_cache_indexability.cpp b/src/mongo/db/query/plan_cache_indexability.cpp new file mode 100644 index 00000000000..ace1c9c278d --- /dev/null +++ b/src/mongo/db/query/plan_cache_indexability.cpp @@ -0,0 +1,82 @@ +/** + * Copyright (C) 2015 10gen Inc. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + * As a special exception, the copyright holders give permission to link the + * code of portions of this program with the OpenSSL library under certain + * conditions as described in each individual source file and distribute + * linked combinations including the program with the OpenSSL library. You + * must comply with the GNU Affero General Public License in all respects for + * all of the code used other than as permitted herein. If you modify file(s) + * with this exception, you may extend this exception to your version of the + * file(s), but you are not obligated to do so. If you do not wish to do so, + * delete this exception statement from your version. If you delete this + * exception statement from all source files in the program, then also delete + * it in the license file. + */ + +#include "mongo/platform/basic.h" + +#include "mongo/db/query/plan_cache_indexability.h" + +#include <memory> +#include "mongo/base/init.h" +#include "mongo/base/owned_pointer_vector.h" +#include "mongo/db/query/index_entry.h" +#include "mongo/db/matcher/expression.h" +#include "mongo/db/matcher/expression_algo.h" +#include "mongo/db/matcher/expression_leaf.h" +#include "mongo/stdx/memory.h" + +namespace mongo { + + void PlanCacheIndexabilityState::processPartialIndex(const MatchExpression* filterExpr) { + invariant(filterExpr); + for (size_t i = 0; i < filterExpr->numChildren(); ++i) { + processPartialIndex(filterExpr->getChild(i)); + } + if (!filterExpr->isLogical()) { + _pathDiscriminatorsMap[filterExpr->path()].push_back( + [filterExpr] (const MatchExpression* queryExpr) { + return expression::isClauseRedundant(queryExpr, filterExpr); + } + ); + } + } + +namespace { + const IndexabilityDiscriminators emptyDiscriminators; +} // namespace + + const IndexabilityDiscriminators& PlanCacheIndexabilityState::getDiscriminators( + StringData path) const { + PathDiscriminatorsMap::const_iterator it = _pathDiscriminatorsMap.find(path); + if (it == _pathDiscriminatorsMap.end()) { + return emptyDiscriminators; + } + return it->second; + } + + void PlanCacheIndexabilityState::updateDiscriminators( + const std::vector<IndexEntry>& indexEntries) { + _pathDiscriminatorsMap = PathDiscriminatorsMap(); + + for (const IndexEntry& idx : indexEntries) { + if (idx.filterExpr) { + processPartialIndex(idx.filterExpr); + } + } + } + +} // namespace mongo |