~drizzle-trunk/drizzle/development

1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
4
 *  Copyright (C) 2008-2009 Sun Microsystems, Inc.
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; version 2 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program; if not, write to the Free Software
17
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 */
19
20
#ifndef DRIZZLED_OPTIMIZER_QUICK_ROR_INTERSECT_SELECT_H
21
#define DRIZZLED_OPTIMIZER_QUICK_ROR_INTERSECT_SELECT_H
22
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
23
#include <drizzled/optimizer/range.h>
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
24
1802.16.6 by Padraig O'Sullivan
Added temporary conversion of a bitmap to dynamic_bitset in order to remove references to MyBitmap within optimizer code.
25
#include <boost/dynamic_bitset.hpp>
1237.13.16 by Padraig O'Sullivan
Replaced List with std::vector in the QuickRorIntersectSelect class.
26
#include <vector>
27
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
28
namespace drizzled
29
{
30
31
namespace optimizer
32
{
33
34
/**
35
  Rowid-Ordered Retrieval (ROR) index intersection quick select.
36
  This quick select produces intersection of row sequences returned
37
  by several QuickRangeSelects it "merges".
38
39
  All merged QuickRangeSelects must return rowids in rowid order.
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
40
  QuickRorIntersectSelect will return rows in rowid order, too.
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
41
42
  All merged quick selects retrieve {rowid, covered_fields} tuples (not full
43
  table records).
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
44
  QuickRorIntersectSelect retrieves full records if it is not being used
45
  by QuickRorIntersectSelect and all merged quick selects together don't
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
46
  cover needed all fields.
47
48
  If one of the merged quick selects is a Clustered PK range scan, it is
49
  used only to filter rowid sequence produced by other merged quick selects.
50
*/
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
51
class QuickRorIntersectSelect : public QuickSelectInterface
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
52
{
53
public:
54
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
55
  QuickRorIntersectSelect(Session *session, 
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
56
                             Table *table,
57
                             bool retrieve_full_rows,
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
58
                             memory::Root *parent_alloc);
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
59
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
60
  ~QuickRorIntersectSelect();
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
61
62
  /**
63
   * Do post-constructor initialization.
64
   * SYNOPSIS
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
65
   * QuickRorIntersectSelect::init()
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
66
   *
67
   * RETURN
68
   * @retval 0      OK
69
   * @retval other  Error code
70
   */
71
  int init();
72
73
  /**
74
   * Initialize quick select for row retrieval.
75
   * SYNOPSIS
76
   * reset()
77
   * RETURN
78
   * @retval 0      OK
79
   * @retval other  Error code
80
   */
81
  int reset(void);
82
83
  /**
84
   * Retrieve next record.
85
   * SYNOPSIS
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
86
   * QuickRorIntersectSelect::get_next()
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
87
   *
88
   * NOTES
89
   * Invariant on enter/exit: all intersected selects have retrieved all index
90
   * records with rowid <= some_rowid_val and no intersected select has
91
   * retrieved any index records with rowid > some_rowid_val.
92
   * We start fresh and loop until we have retrieved the same rowid in each of
93
   * the key scans or we got an error.
94
   *
95
   * If a Clustered PK scan is present, it is used only to check if row
96
   * satisfies its condition (and never used for row retrieval).
97
   *
98
   * RETURN
99
   * @retval 0     - Ok
100
   * @retval other - Error code if any error occurred.
101
   */
102
  int get_next();
103
104
  bool reverse_sorted() const
105
  {
106
    return false;
107
  }
108
109
  bool unique_key_range() const
110
  {
111
    return false;
112
  }
113
114
  int get_type() const
115
  {
116
    return QS_TYPE_ROR_INTERSECT;
117
  }
118
2170.4.4 by Stewart Smith
tmp3 String to std::string in explain_plan (and used_lengths parameter to add_keys_and_lengths
119
  void add_keys_and_lengths(std::string *key_names, std::string *used_lengths);
2170.4.5 by Stewart Smith
convert explain_plan extra String to std::string. This means that add_info_string() also gets converted to std::string
120
  void add_info_string(std::string *str);
1802.16.6 by Padraig O'Sullivan
Added temporary conversion of a bitmap to dynamic_bitset in order to remove references to MyBitmap within optimizer code.
121
  bool is_keys_used(const boost::dynamic_bitset<>& fields);
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
122
123
  /**
124
   * Initialize this quick select to be a part of a ROR-merged scan.
125
   * SYNOPSIS
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
126
   * QuickRorIntersectSelect::init_ror_merged_scan()
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
127
   * reuse_handler If true, use head->cursor, otherwise create separate
128
   * Cursor object.
129
   * RETURN
130
   * @retval 0     OK
131
   * @retval other error code
132
   */
133
  int init_ror_merged_scan(bool reuse_handler);
134
135
  /**
136
   * Add a merged quick select to this ROR-intersection quick select.
137
   *
138
   * SYNOPSIS
1237.13.12 by Padraig O'Sullivan
Corrected the name of the QUICK_ROR_INTERSECT_CLASS class to adhere to the drizzle coding standards.
139
   * QuickRorIntersectSelect::push_quick_back()
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
140
   * quick Quick select to be added. The quick select must return
141
   * rows in rowid order.
142
   * NOTES
143
   * This call can only be made before init() is called.
144
   *
145
   * RETURN
146
   * @retval false OK
147
   * @retval true  Out of memory.
148
   */
149
  bool push_quick_back(QuickRangeSelect *quick_sel_range);
150
151
  /**
152
   * Range quick selects this intersection consists of, not including
153
   * cpk_quick.
154
   */
1237.13.16 by Padraig O'Sullivan
Replaced List with std::vector in the QuickRorIntersectSelect class.
155
  std::vector<QuickRangeSelect *> quick_selects;
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
156
157
  /**
158
   * Merged quick select that uses Clustered PK, if there is one. This quick
159
   * select is not used for row retrieval, it is used for row retrieval.
160
   */
161
  QuickRangeSelect *cpk_quick;
162
1280.1.10 by Monty Taylor
Put everything in drizzled into drizzled namespace.
163
  memory::Root alloc; /**< Memory pool for this and merged quick selects data. */
1237.13.11 by Padraig O'Sullivan
Split the QUICK_ROR_INTERSECT_SELECT class out into its own header and implementation files.
164
  Session *session; /**< Pointer to the current session */
165
  bool need_to_fetch_row; /**< if true, do retrieve full table records. */
166
  /** in top-level quick select, true if merged scans where initialized */
167
  bool scans_inited;
168
};
169
170
} /* namespace optimizer */
171
172
} /* namespace drizzled */
173
174
#endif /* DRIZZLED_OPTIMIZER_QUICK_ROR_INTERSECT_SELECT_H */