~vadim-tk/percona-server/flushing-algo

« back to all changes in this revision

Viewing changes to storage/ndb/include/ndbapi/NdbScanFilter.hpp

  • Committer: root
  • Date: 2011-10-29 01:34:40 UTC
  • Revision ID: root@hppro1.office.percona.com-20111029013440-qhnf4jk8kdjcf4e0
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2003 MySQL AB
 
2
 
 
3
   This program is free software; you can redistribute it and/or modify
 
4
   it under the terms of the GNU General Public License as published by
 
5
   the Free Software Foundation; version 2 of the License.
 
6
 
 
7
   This program is distributed in the hope that it will be useful,
 
8
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
   GNU General Public License for more details.
 
11
 
 
12
   You should have received a copy of the GNU General Public License
 
13
   along with this program; if not, write to the Free Software
 
14
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */
 
15
 
 
16
#ifndef NDB_SCAN_FILTER_HPP
 
17
#define NDB_SCAN_FILTER_HPP
 
18
 
 
19
#include <ndb_types.h>
 
20
#include <ndbapi_limits.h>
 
21
 
 
22
/**
 
23
 * @class NdbScanFilter
 
24
 * @brief A simple way to specify filters for scan operations
 
25
 *
 
26
 * @note  This filter interface is under development and may change in 
 
27
 *        the future! 
 
28
 * 
 
29
 */
 
30
class NdbScanFilter {
 
31
public:
 
32
  /**
 
33
   * Constructor
 
34
   * @param op  The NdbOperation that the filter belongs to (is applied to).
 
35
   * @param abort_on_too_large  abort transaction on filter too large
 
36
   *                            default: true
 
37
   * @param max_size  Maximum size of generated filter in words
 
38
   */
 
39
  NdbScanFilter(class NdbOperation * op,
 
40
                bool abort_on_too_large = true,
 
41
                Uint32 max_size = NDB_MAX_SCANFILTER_SIZE_IN_WORDS);
 
42
  ~NdbScanFilter();
 
43
  
 
44
  /**
 
45
   *  Group operators
 
46
   */
 
47
  enum Group {
 
48
    AND  = 1,    ///< (x1 AND x2 AND x3)
 
49
    OR   = 2,    ///< (x1 OR x2 OR X3)
 
50
    NAND = 3,    ///< NOT (x1 AND x2 AND x3)
 
51
    NOR  = 4     ///< NOT (x1 OR x2 OR x3)
 
52
  };
 
53
 
 
54
  enum BinaryCondition 
 
55
  {
 
56
    COND_LE = 0,        ///< lower bound
 
57
    COND_LT = 1,        ///< lower bound, strict
 
58
    COND_GE = 2,        ///< upper bound
 
59
    COND_GT = 3,        ///< upper bound, strict
 
60
    COND_EQ = 4,        ///< equality
 
61
    COND_NE = 5,        ///< not equal
 
62
    COND_LIKE = 6,      ///< like
 
63
    COND_NOT_LIKE = 7   ///< not like
 
64
  };
 
65
 
 
66
  /** 
 
67
   * @name Grouping
 
68
   * @{
 
69
   */
 
70
 
 
71
  /**
 
72
   *  Begin of compound.
 
73
   *  �return  0 if successful, -1 otherwize
 
74
   */
 
75
  int begin(Group group = AND);    
 
76
 
 
77
  /**
 
78
   *  End of compound.
 
79
   *  �return  0 if successful, -1 otherwize
 
80
   */
 
81
  int end();
 
82
 
 
83
  /** @} *********************************************************************/
 
84
 
 
85
  /**
 
86
   *  <i>Explanation missing</i>
 
87
   */
 
88
  int istrue();
 
89
 
 
90
  /**
 
91
   *  <i>Explanation missing</i>
 
92
   */
 
93
  int isfalse();
 
94
 
 
95
  /**
 
96
   * Compare column <b>ColId</b> with <b>val</b>
 
97
   */
 
98
  int cmp(BinaryCondition cond, int ColId, const void *val, Uint32 len = 0); 
 
99
 
 
100
  /** 
 
101
   * @name Integer Comparators
 
102
   * @{
 
103
   */
 
104
  /** Compare column value with integer for equal   
 
105
   *  �return  0 if successful, -1 otherwize
 
106
   */
 
107
  int eq(int ColId, Uint32 value) { return cmp(COND_EQ, ColId, &value, 4);}
 
108
 
 
109
  /** Compare column value with integer for not equal.
 
110
   *  �return  0 if successful, -1 otherwize 
 
111
   */
 
112
  int ne(int ColId, Uint32 value) { return cmp(COND_NE, ColId, &value, 4);}  
 
113
  /** Compare column value with integer for less than.
 
114
   *  �return  0 if successful, -1 otherwize 
 
115
   */
 
116
  int lt(int ColId, Uint32 value) { return cmp(COND_LT, ColId, &value, 4);}
 
117
  /** Compare column value with integer for less than or equal. 
 
118
   *  �return  0 if successful, -1 otherwize
 
119
   */
 
120
  int le(int ColId, Uint32 value) { return cmp(COND_LE, ColId, &value, 4);}
 
121
  /** Compare column value with integer for greater than. 
 
122
   *  �return  0 if successful, -1 otherwize
 
123
   */
 
124
  int gt(int ColId, Uint32 value) { return cmp(COND_GT, ColId, &value, 4);} 
 
125
  /** Compare column value with integer for greater than or equal.
 
126
   *  �return  0 if successful, -1 otherwize
 
127
   */
 
128
  int ge(int ColId, Uint32 value) { return cmp(COND_GE, ColId, &value, 4);}
 
129
 
 
130
  /** Compare column value with integer for equal. 64-bit.  
 
131
   *  �return  0 if successful, -1 otherwize
 
132
   */
 
133
  int eq(int ColId, Uint64 value) { return cmp(COND_EQ, ColId, &value, 8);}
 
134
  /** Compare column value with integer for not equal. 64-bit.
 
135
   *  �return  0 if successful, -1 otherwize
 
136
   */
 
137
  int ne(int ColId, Uint64 value) { return cmp(COND_NE, ColId, &value, 8);}
 
138
  /** Compare column value with integer for less than. 64-bit.
 
139
   *  �return  0 if successful, -1 otherwize
 
140
   */
 
141
  int lt(int ColId, Uint64 value) { return cmp(COND_LT, ColId, &value, 8);}  
 
142
  /** Compare column value with integer for less than or equal. 64-bit.
 
143
   *  �return  0 if successful, -1 otherwize
 
144
   */
 
145
  int le(int ColId, Uint64 value) { return cmp(COND_LE, ColId, &value, 8);}
 
146
  /** Compare column value with integer for greater than. 64-bit.
 
147
   *  �return  0 if successful, -1 otherwize
 
148
   */
 
149
  int gt(int ColId, Uint64 value) { return cmp(COND_GT, ColId, &value, 8);}
 
150
  /** Compare column value with integer for greater than or equal. 64-bit.
 
151
   *  �return  0 if successful, -1 otherwize
 
152
   */
 
153
  int ge(int ColId, Uint64 value) { return cmp(COND_GE, ColId, &value, 8);}
 
154
  /** @} *********************************************************************/
 
155
 
 
156
  /** Check if column value is NULL */
 
157
  int isnull(int ColId);             
 
158
  /** Check if column value is non-NULL */
 
159
  int isnotnull(int ColId);          
 
160
  
 
161
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
 
162
  /**
 
163
   *  Like comparison operator.
 
164
   *  �return  0 if successful, -1 otherwize
 
165
   */
 
166
  int like(int ColId, const char * val, Uint32 len, bool nopad=false);
 
167
  /**
 
168
   *  Notlike comparison operator.
 
169
   *  �return  0 if successful, -1 otherwize
 
170
   */
 
171
  int notlike(int ColId, const char * val, Uint32 len, bool nopad=false);
 
172
  /** @} *********************************************************************/
 
173
#endif
 
174
 
 
175
  enum Error {
 
176
    FilterTooLarge = 4294
 
177
  };
 
178
 
 
179
  /**
 
180
   * Get filter level error.
 
181
   *
 
182
   * Most errors are set only on operation level, and they abort the
 
183
   * transaction.  The error FilterTooLarge is set on filter level and
 
184
   * by default it propagates to operation level and also aborts the
 
185
   * transaction.
 
186
   *
 
187
   * If option abort_on_too_large is set to false, then FilterTooLarge
 
188
   * does not propagate.  One can then either ignore this error (in
 
189
   * which case no filtering is done) or try to define a new filter
 
190
   * immediately.
 
191
   */
 
192
  const class NdbError & getNdbError() const;
 
193
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
 
194
  NdbOperation * getNdbOperation();
 
195
#endif
 
196
private:
 
197
#ifndef DOXYGEN_SHOULD_SKIP_INTERNAL
 
198
  friend class NdbScanFilterImpl;
 
199
#endif
 
200
  class NdbScanFilterImpl & m_impl;
 
201
  NdbScanFilter& operator=(const NdbScanFilter&); ///< Defined not implemented
 
202
};
 
203
 
 
204
#endif