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