summaryrefslogtreecommitdiff
path: root/src/mongo/db/query/get_runner.h
blob: 2d9dd75c88e2b2f1404402db835ca9f9e9dc1f61 (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
/**
 *    Copyright (C) 2013-2014 MongoDB 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 -- replaced by get_executor.h

#include "mongo/db/query/canonical_query.h"
#include "mongo/db/query/query_planner_params.h"
#include "mongo/db/query/query_settings.h"
#include "mongo/db/query/query_solution.h"
#include "mongo/db/query/runner.h"

namespace mongo {

    class Collection;
    class OperationContext;

    /**
     * Get a runner for a query.  Takes ownership of rawCanonicalQuery.
     *
     * If the query is valid and a runner could be created, returns Status::OK()
     * and populates *out with the Runner.
     *
     * If the query cannot be executed, returns a Status indicating why.  Deletes
     * rawCanonicalQuery.
     */
    Status getRunner(OperationContext* txn,
                     Collection* collection,
                     CanonicalQuery* rawCanonicalQuery,
                     Runner** out,
                     size_t plannerOptions = 0);

    /**
     * Gets a runner for a query described as an unparsed BSON object over the named and optionally
     * supplied collection.
     *
     * If necessary, parses a CanonicalQuery out of 'unparsedQuery'.
     *
     * Returns Status::OK() on success, in which case '*outRunner' points to a runner now owned by
     * the caller, and '*outCanonicalQuery' is either NULL or points to a canonical query owned by
     * the returned runner.  On failure, returns other status values, and '*outRunner' and
     * '*outCanonicalQuery' have unspecified values.
     */
    Status getRunner(OperationContext* txn,
                     Collection* collection,
                     const std::string& ns,
                     const BSONObj& unparsedQuery,
                     Runner** outRunner,
                     CanonicalQuery** outCanonicalQuery,
                     size_t plannerOptions = 0);
    /*
     * Get a runner for a query executing as part of a distinct command.
     *
     * Distinct is unique in that it doesn't care about getting all the results; it just wants all
     * possible values of a certain field.  As such, we can skip lots of data in certain cases (see
     * body of method for detail).
     */
    Status getRunnerDistinct(OperationContext* txn,
                             Collection* collection,
                             const BSONObj& query,
                             const std::string& field,
                             Runner** out);

    /*
     * Get a runner for a query executing as part of a count command.
     *
     * Count doesn't care about actually examining its results; it just wants to walk through them.
     * As such, with certain covered queries, we can skip the overhead of fetching etc. when
     * executing a count.
     */
    Status getRunnerCount(OperationContext* txn,
                          Collection* collection,
                          const BSONObj& query,
                          const BSONObj& hintObj,
                          Runner** out);

    /**
     * Get a runner for a query.  Ignores the cache and always plans the full query.
     */
    Status getRunnerAlwaysPlan(OperationContext* txn,
                               Collection* collection,
                               CanonicalQuery* rawCanonicalQuery,
                               const QueryPlannerParams& plannerParams,
                               Runner** out);

    /**
     * RAII approach to ensuring that runners are deregistered in newRunQuery.
     *
     * While retrieving the first batch of results, newRunQuery manually registers the runner with
     * ClientCursor.  Certain query execution paths, namely $where, can throw an exception.  If we
     * fail to deregister the runner, we will call invalidate/kill on the
     * still-registered-yet-deleted runner.
     *
     * For any subsequent calls to getMore, the runner is already registered with ClientCursor
     * by virtue of being cached, so this exception-proofing is not required.
     */
    struct ScopedRunnerRegistration {
        ScopedRunnerRegistration(Runner* runner);
        ~ScopedRunnerRegistration();

        Runner* const _runner;
    };

}  // namespace mongo