~ubuntu-branches/ubuntu/utopic/mongodb/utopic

« back to all changes in this revision

Viewing changes to src/mongo/db/explain.h

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-07-03 09:23:46 UTC
  • mfrom: (1.3.10) (44.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20140703092346-c5bvt46wnzougyly
Tags: 1:2.6.3-0ubuntu1
* New upstream stable release:
  - Dropped patches, included upstream:
    + 0003-All-platforms-but-Windows-find-hash-in-std-tr1.patch
    + 0008-Use-system-libstemmer.patch
    + 0011-Use-a-signed-char-to-store-BSONType-enumerations.patch
    + 0001-SERVER-12064-Atomic-operations-for-gcc-non-Intel-arc.patch
    + 0002-SERVER-12065-Support-ARM-and-AArch64-builds.patch
  - d/p/*: Refreshed/rebased remaining patches.
  - Use system provided libyaml-cpp:
    + d/control: Add libyaml-cpp-dev to BD's.
    + d/rules: Enable --with-system-yaml option.
    + d/p/fix-yaml-detection.patch: Fix detection of libyaml-cpp library.
  - d/mongodb-server.mongodb.upstart: Sync changes from upstream.
  - d/control,mongodb-dev.*: Drop mongodb-dev package; it has no reverse
    dependencies and upstream no longer install header files.
  - d/NEWS: Point users to upstream upgrade documentation for upgrades
    from 2.4 to 2.6.
* Merge from Debian unstable.
* d/control: BD on libv8-3.14-dev to ensure that transitioning to new v8
  versions is a explicit action due to changes in behaviour in >= 3.25
  (LP: #1295723).
* d/mongodb-server.prerm: Dropped debug echo call from maintainer script
  (LP: #1294455).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// @file explain.h - Helper classes for generating query explain output.
2
 
 
3
 
/*    Copyright 2012 10gen Inc.
4
 
 *
5
 
 *    Licensed under the Apache License, Version 2.0 (the "License");
6
 
 *    you may not use this file except in compliance with the License.
7
 
 *    You may obtain a copy of the License at
8
 
 *
9
 
 *    http://www.apache.org/licenses/LICENSE-2.0
10
 
 *
11
 
 *    Unless required by applicable law or agreed to in writing, software
12
 
 *    distributed under the License is distributed on an "AS IS" BASIS,
13
 
 *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 
 *    See the License for the specific language governing permissions and
15
 
 *    limitations under the License.
16
 
 */
17
 
 
18
 
#pragma once
19
 
 
20
 
#include "cursor.h"
21
 
#include "../util/timer.h"
22
 
 
23
 
namespace mongo {
24
 
    
25
 
    /**
26
 
     * Note: by default we filter out allPlans and oldPlan in the shell's
27
 
     * explain() function. If you add any recursive structures, make sure to
28
 
     * edit the JS to make sure everything gets filtered.
29
 
     */
30
 
    
31
 
    /** The timer starts on construction and provides the duration since then or until stopped. */
32
 
    class DurationTimer {
33
 
    public:
34
 
        DurationTimer() : _running( true ), _duration() {}
35
 
        void stop() { _running = false; _duration = _timer.millis(); }
36
 
        int duration() const { return _running ? _timer.millis() : _duration; }
37
 
    private:
38
 
        Timer _timer;
39
 
        bool _running;
40
 
        int _duration;
41
 
    };
42
 
    
43
 
    class ExplainClauseInfo;
44
 
    
45
 
    /** Data describing execution of a query plan. */
46
 
    class ExplainPlanInfo {
47
 
    public:
48
 
        ExplainPlanInfo();
49
 
 
50
 
        /** Note information about the plan. */
51
 
        void notePlan( const Cursor &cursor, bool scanAndOrder, bool indexOnly );
52
 
        /** Note an iteration of the plan. */
53
 
        void noteIterate( bool match, bool loadedRecord, const Cursor &cursor );
54
 
        /** Note that the plan finished execution. */
55
 
        void noteDone( const Cursor &cursor );
56
 
        /** Note that the plan was chosen over others by the query optimizer. */
57
 
        void notePicked();
58
 
 
59
 
        /** BSON summary of the plan. */
60
 
        BSONObj bson() const;
61
 
        /** Combined details of both the plan and its clause. */
62
 
        BSONObj pickedPlanBson( const ExplainClauseInfo &clauseInfo ) const;
63
 
 
64
 
        bool picked() const { return _picked; }
65
 
        bool done() const { return _done; }
66
 
        long long n() const { return _n; }
67
 
        long long nscannedObjects() const { return _nscannedObjects; }
68
 
        long long nscanned() const { return _nscanned; }
69
 
 
70
 
    private:
71
 
        void noteCursorUpdate( const Cursor &cursor );
72
 
        string _cursorName;
73
 
        bool _isMultiKey;
74
 
        long long _n;
75
 
        long long _nscannedObjects;
76
 
        long long _nscanned;
77
 
        bool _scanAndOrder;
78
 
        bool _indexOnly;
79
 
        BSONObj _indexBounds;
80
 
        bool _picked;
81
 
        bool _done;
82
 
        BSONObj _details;
83
 
    };
84
 
    
85
 
    /** Data describing execution of a query clause. */
86
 
    class ExplainClauseInfo {
87
 
    public:
88
 
        ExplainClauseInfo();
89
 
 
90
 
        /** Note an iteration of the clause. */
91
 
        void noteIterate( bool match, bool loadedRecord, bool chunkSkip );
92
 
        /** Note a yield for the clause. */
93
 
        void noteYield();
94
 
        /** Revise the total number of documents returned to match an external count. */
95
 
        void reviseN( long long n );
96
 
        /** Stop the clauses's timer. */
97
 
        void stopTimer();
98
 
 
99
 
        /** Add information about a plan to this clause. */
100
 
        void addPlanInfo( const shared_ptr<ExplainPlanInfo> &info );
101
 
        BSONObj bson() const;
102
 
 
103
 
        long long n() const { return _n; }
104
 
        long long nscannedObjects() const;
105
 
        long long nscanned() const;
106
 
        long long nscannedObjectsAllPlans() const { return _nscannedObjects; }
107
 
        long long nscannedAllPlans() const;
108
 
        long long nChunkSkips() const { return _nChunkSkips; }
109
 
        int nYields() const { return _nYields; }
110
 
        int millis() const { return _timer.duration(); }
111
 
 
112
 
    private:
113
 
        /**
114
 
         * @return Plan explain information to be displayed at the top of the explain output.  A
115
 
         * picked() plan will be returned if one is available, otherwise a successful non picked()
116
 
         * plan will be returned.
117
 
         */
118
 
        const ExplainPlanInfo &virtualPickedPlan() const;
119
 
        list<shared_ptr<const ExplainPlanInfo> > _plans;
120
 
        long long _n;
121
 
        long long _nscannedObjects;
122
 
        long long _nChunkSkips;
123
 
        int _nYields;
124
 
        DurationTimer _timer;
125
 
    };
126
 
    
127
 
    /** Data describing execution of a query. */
128
 
    class ExplainQueryInfo {
129
 
    public:
130
 
        /** Note an iteration of the query's current clause. */
131
 
        void noteIterate( bool match, bool loadedRecord, bool chunkSkip );
132
 
        /** Note a yield of the query's current clause. */
133
 
        void noteYield();
134
 
        /** Revise the number of documents returned by the current clause. */
135
 
        void reviseN( long long n );
136
 
 
137
 
        /* Additional information describing the query. */
138
 
        struct AncillaryInfo {
139
 
            BSONObj _oldPlan;
140
 
        };
141
 
        void setAncillaryInfo( const AncillaryInfo &ancillaryInfo );
142
 
        
143
 
        /* Add information about a clause to this query. */
144
 
        void addClauseInfo( const shared_ptr<ExplainClauseInfo> &info );
145
 
        BSONObj bson() const;
146
 
 
147
 
    private:
148
 
        static string server();
149
 
        
150
 
        list<shared_ptr<ExplainClauseInfo> > _clauses;
151
 
        AncillaryInfo _ancillaryInfo;
152
 
        DurationTimer _timer;
153
 
    };
154
 
    
155
 
    /** Data describing execution of a query with a single clause and plan. */
156
 
    class ExplainSinglePlanQueryInfo {
157
 
    public:
158
 
        ExplainSinglePlanQueryInfo();
159
 
 
160
 
        /** Note information about the plan. */
161
 
        void notePlan( const Cursor &cursor, bool scanAndOrder, bool indexOnly ) {
162
 
            _planInfo->notePlan( cursor, scanAndOrder, indexOnly );
163
 
        }
164
 
        /** Note an iteration of the plan and the clause. */
165
 
        void noteIterate( bool match, bool loadedRecord, bool chunkSkip, const Cursor &cursor ) {
166
 
            _planInfo->noteIterate( match, loadedRecord, cursor );
167
 
            _queryInfo->noteIterate( match, loadedRecord, chunkSkip );
168
 
        }
169
 
        /** Note a yield for the clause. */
170
 
        void noteYield() {
171
 
            _queryInfo->noteYield();
172
 
        }
173
 
        /** Note that the plan finished execution. */
174
 
        void noteDone( const Cursor &cursor ) {
175
 
            _planInfo->noteDone( cursor );
176
 
        }
177
 
 
178
 
        /** Return the corresponding ExplainQueryInfo for further use. */
179
 
        shared_ptr<ExplainQueryInfo> queryInfo() const {
180
 
            return _queryInfo;
181
 
        }
182
 
 
183
 
    private:
184
 
        shared_ptr<ExplainPlanInfo> _planInfo;
185
 
        shared_ptr<ExplainQueryInfo> _queryInfo;
186
 
    };
187
 
 
188
 
} // namespace mongo