blob: b76d78e16cdbc99b7d0a21be5acc667de23f10b6 (
plain)
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
|
/**
* Copyright (C) 2013 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/>.
*/
#pragma once
#include "mongo/db/jsobj.h"
#include "mongo/db/matcher/expression_parser.h"
#include "mongo/db/query/index_bounds.h"
namespace mongo {
/**
* Translates expressions over fields into bounds on an index.
*/
class IndexBoundsBuilder {
public:
/**
* Return an O.I.L. with one interval goes from MinKey to MaxKey (or vice-versa depending on
* the index direction).
*/
static OrderedIntervalList allValuesForField(const BSONElement& elt);
/**
* Turn the LeafMatchExpression in 'expr' into a set of index bounds. The field that 'expr'
* is concerned with is indexed according to 'idxElt'.
*/
static void translate(const LeafMatchExpression* expr, const BSONElement& idxElt,
OrderedIntervalList* oilOut, bool* exactOut);
private:
/**
* Make a range interval from the provided object.
* The object must have exactly two fields. The first field is the start, the second the
* end.
* The two inclusive flags indicate whether or not the start/end fields are included in the
* interval (closed interval if included, open if not).
*/
static Interval makeRangeInterval(const BSONObj& obj, bool startInclusive,
bool endInclusive);
/**
* Make a point interval from the provided object.
* The object must have exactly one field which is the value of the point interval.
*/
static Interval makePointInterval(const BSONObj& obj);
/**
* Since we have no BSONValue we must make an object that's a copy of a piece of another
* object.
*/
static BSONObj objFromElement(const BSONElement& elt);
/**
* Swap start/end in the provided interval.
*/
static void reverseInterval(Interval* ival);
};
} // namespace mongo
|