~drizzle-trunk/drizzle/development

1108.6.39 by Padraig O'Sullivan
Placed the SargableParam class in the optimizer namespace and sub-directory.
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
 *
4
 *  Copyright (C) 2009 Sun Microsystems
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_SARGABLE_PARAM_H
21
#define DRIZZLED_OPTIMIZER_SARGABLE_PARAM_H
22
23
namespace drizzled
24
{
25
namespace optimizer
26
{
27
28
/**
29
 * SARG stands for search argument. A sargable predicate is one of the form
30
 * (or which can be put in to the form) "column comparison-operator value".
31
 * SARGS are expressed as a boolean expression of such predicates in
32
 * disjunctive normal form. For more information, consult the original paper
33
 * in which this term was introduced: Access Path Selection in a Relational
34
 * Database Management System by Selinger et al
35
 *
36
 * This class is used to collect info on potentially sargable predicates in
37
 * order to check whether they become sargable after reading const tables.
38
 * We form a bitmap of indexes that can be used for sargable predicates.
39
 * Only such indexes are involved in range analysis.
40
 */
41
class SargableParam
42
{
43
public:
44
  SargableParam()
45
    :
46
      field(NULL),
47
      arg_value(NULL),
48
      num_values(0)
49
  {}
50
51
  SargableParam(Field *in_field,
52
                Item **in_arg_value,
53
                uint32_t in_num_values)
54
    :
55
      field(in_field),
56
      arg_value(in_arg_value),
57
      num_values(in_num_values)
58
  {}
59
1108.6.51 by Padraig O'Sullivan
Added a copy constructor and assignment operator to the SargableParam class.
60
  SargableParam(const SargableParam &rhs)
61
    :
62
      field(rhs.field),
63
      arg_value(rhs.arg_value),
64
      num_values(rhs.num_values)
65
  {}
66
67
  SargableParam &operator=(const SargableParam &rhs)
68
  {
69
    if (this == &rhs)
70
    {
71
      return *this;
72
    }
73
    field= rhs.field;
74
    arg_value= rhs.arg_value;
75
    num_values= rhs.num_values;
76
    return *this;
77
  }
78
1108.6.39 by Padraig O'Sullivan
Placed the SargableParam class in the optimizer namespace and sub-directory.
79
  Field *getField()
80
  {
81
    return field;
82
  }
83
84
  uint32_t getNumValues() const
85
  {
86
    return num_values;
87
  }
88
89
  bool isConstItem(uint32_t index)
90
  {
91
    return (arg_value[index]->const_item());
92
  }
93
94
private:
95
96
  /**
97
   * Field agsinst which to check sargability.
98
   */
99
  Field *field;
100
101
  /**
102
   * Values of potential keys for lookups.
103
   */
104
  Item **arg_value;
105
106
  /**
107
   * Number of values in the arg_value array.
108
   */
109
  uint32_t num_values;
110
};
111
112
} /* end namespace optimizer */
113
114
} /* end namespace drizzled */
115
116
#endif /* DRIZZLED_OPTIMIZER_SARGABLE_PARAM_H */