summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/type_explain.h
blob: 6cca71f2bf0f87cfb868758a70968b093bde34ff (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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
/**
 *    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/>.
 *
 *    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.
 */

// THIS FILE IS DEPRECATED -- the old explain implementation is being replaced

#pragma once

#include <string>

#include "mongo/base/string_data.h"
#include "mongo/bson/bson_field.h"
#include "mongo/s/bson_serializable.h"

namespace mongo {

    /**
     * Contains query debug information that describes the
     * query plan. Generally this information depends only on
     * the planning process that happens without running the
     * query. The exception is the multi plan runner, in which
     * case plan selection depends on actually running the query.
     *
     * Currently, just a summary std::string describing the plan
     * used to run the query.
     */
    struct PlanInfo {
        PlanInfo() : planSummary("") { }
        std::string planSummary;
    };

    /**
     * This class represents the layout and content of a TypeExplain runCommand,
     * the response side.
     */
    class TypeExplain : public BSONSerializable {
        MONGO_DISALLOW_COPYING(TypeExplain);
    public:

        //
        // schema declarations
        //

        static const BSONField<std::vector<TypeExplain*> > clauses;
        static const BSONField<std::string> cursor;
        static const BSONField<bool> isMultiKey;
        static const BSONField<long long> n;
        static const BSONField<long long> nScannedObjects;
        static const BSONField<long long> nScanned;
        static const BSONField<long long> nScannedObjectsAllPlans;
        static const BSONField<long long> nScannedAllPlans;
        static const BSONField<bool> scanAndOrder;
        static const BSONField<bool> indexOnly;
        static const BSONField<long long> nYields;
        static const BSONField<long long> nChunkSkips;
        static const BSONField<long long> millis;
        static const BSONField<BSONObj> indexBounds;
        static const BSONField<std::vector<TypeExplain*> > allPlans;
        static const BSONField<TypeExplain*> oldPlan;
        static const BSONField<bool> indexFilterApplied;
        static const BSONField<std::string> server;

        //
        // construction / destruction
        //

        TypeExplain();
        virtual ~TypeExplain();

        /** Copies all the fields present in 'this' to 'other'. */
        void cloneTo(TypeExplain* other) const;

        //
        // bson serializable interface implementation
        //

        virtual bool isValid(std::string* errMsg) const;
        virtual BSONObj toBSON() const;
        virtual bool parseBSON(const BSONObj& source, std::string* errMsg);
        virtual void clear();
        virtual std::string toString() const;

        //
        // individual field accessors
        //

        void setClauses(const std::vector<TypeExplain*>& clauses);
        void addToClauses(TypeExplain* clauses);
        void unsetClauses();
        bool isClausesSet() const;
        size_t sizeClauses() const;
        const std::vector<TypeExplain*>& getClauses() const;
        const TypeExplain* getClausesAt(size_t pos) const;

        void setCursor(const StringData& cursor);
        void unsetCursor();
        bool isCursorSet() const;
        const std::string& getCursor() const;

        void setIsMultiKey(bool isMultiKey);
        void unsetIsMultiKey();
        bool isIsMultiKeySet() const;
        bool getIsMultiKey() const;

        void setN(long long n);
        void unsetN();
        bool isNSet() const;
        long long getN() const;

        void setNScannedObjects(long long nScannedObjects);
        void unsetNScannedObjects();
        bool isNScannedObjectsSet() const;
        long long getNScannedObjects() const;

        void setNScanned(long long nScanned);
        void unsetNScanned();
        bool isNScannedSet() const;
        long long getNScanned() const;

        void setNScannedObjectsAllPlans(long long nScannedObjectsAllPlans);
        void unsetNScannedObjectsAllPlans();
        bool isNScannedObjectsAllPlansSet() const;
        long long getNScannedObjectsAllPlans() const;

        void setNScannedAllPlans(long long nScannedAllPlans);
        void unsetNScannedAllPlans();
        bool isNScannedAllPlansSet() const;
        long long getNScannedAllPlans() const;

        void setScanAndOrder(bool scanAndOrder);
        void unsetScanAndOrder();
        bool isScanAndOrderSet() const;
        bool getScanAndOrder() const;

        void setIndexOnly(bool indexOnly);
        void unsetIndexOnly();
        bool isIndexOnlySet() const;
        bool getIndexOnly() const;

        void setIDHack(bool idhack);
        void unsetIDHack();
        bool isIDHackSet() const;
        bool getIDHack() const;

        void setIndexFilterApplied(bool indexFilterApplied);
        void unsetIndexFilterApplied();
        bool isIndexFilterAppliedSet() const;
        bool getIndexFilterApplied() const;

        void setNYields(long long nYields);
        void unsetNYields();
        bool isNYieldsSet() const;
        long long getNYields() const;

        void setNChunkSkips(long long nChunkSkips);
        void unsetNChunkSkips();
        bool isNChunkSkipsSet() const;
        long long getNChunkSkips() const;

        void setMillis(long long millis);
        void unsetMillis();
        bool isMillisSet() const;
        long long getMillis() const;

        void setIndexBounds(const BSONObj& indexBounds);
        void unsetIndexBounds();
        bool isIndexBoundsSet() const;
        const BSONObj& getIndexBounds() const;

        void setAllPlans(const std::vector<TypeExplain*>& allPlans);
        void addToAllPlans(TypeExplain* allPlans);
        void unsetAllPlans();
        bool isAllPlansSet() const;
        size_t sizeAllPlans() const;
        const std::vector<TypeExplain*>& getAllPlans() const;
        const TypeExplain* getAllPlansAt(size_t pos) const;

        void setOldPlan(TypeExplain* oldPlan);
        void unsetOldPlan();
        bool isOldPlanSet() const;
        const TypeExplain* getOldPlan() const;

        void setServer(const StringData& server);
        void unsetServer();
        bool isServerSet() const;
        const std::string& getServer() const;

        // Opaque stats object
        BSONObj stats;

    private:
        // Convention: (M)andatory, (O)ptional

        // (O)  explain for branches on a $or query
        boost::scoped_ptr<std::vector<TypeExplain*> >_clauses;

        // (O)  type and name of the cursor used on the leaf stage
        std::string _cursor;
        bool _isCursorSet;

        // (O)  type and name of the cursor used on the leaf stage
        bool _isMultiKey;
        bool _isIsMultiKeySet;

        // (M)  number of documents returned by the query
        long long _n;
        bool _isNSet;

        // (M)  number of documents fetched entirely from the disk
        long long _nScannedObjects;
        bool _isNScannedObjectsSet;

        // (M)  number of entries retrieved either from an index or collection
        long long _nScanned;
        bool _isNScannedSet;

        // (O)  number of documents fetched entirely from the disk across all plans
        long long _nScannedObjectsAllPlans;
        bool _isNScannedObjectsAllPlansSet;

        // (O)  number of entries retrieved either from an index or collection across all plans
        long long _nScannedAllPlans;
        bool _isNScannedAllPlansSet;

        // (O)  whether this plan involved sorting
        bool _scanAndOrder;
        bool _isScanAndOrderSet;

        // (O)  number of entries retrieved either from an index or collection across all plans
        bool _indexOnly;
        bool _isIndexOnlySet;

        // (O)  whether the idhack was used to answer this query
        bool _idHack;
        bool _isIDHackSet;

        // (O)  whether index filters were used in planning this query
        bool _indexFilterApplied;
        bool _isIndexFilterAppliedSet;

        // (O)  number times this plan released and reacquired its lock
        long long _nYields;
        bool _isNYieldsSet;

        // (O)  number times this plan skipped over migrated data
        long long _nChunkSkips;
        bool _isNChunkSkipsSet;

        // (O)  elapsed time this plan took running, in milliseconds
        long long _millis;
        bool _isMillisSet;

        // (O)  keys used to seek in and out of an index
        BSONObj _indexBounds;
        bool _isIndexBoundsSet;

        // (O)  alternative plans considered
        boost::scoped_ptr<std::vector<TypeExplain*> > _allPlans;

        // (O)  cached plan for this query
        boost::scoped_ptr<TypeExplain> _oldPlan;

        // (O)  server's host:port against which the query ran
        std::string _server;
        bool _isServerSet;
    };

} // namespace mongo