~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/identifier/table.h

  • Committer: Brian Aker
  • Date: 2010-09-15 20:24:31 UTC
  • mto: (1766.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 1767.
  • Revision ID: brian@tangent.org-20100915202431-wbrrl4vg6rzjvdiu
Adding opt for optional schedulers and making them --plugin-add only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
{
59
59
public:
60
60
  typedef message::Table::TableType Type;
61
 
  typedef std::vector <TableIdentifier> vector;
62
 
  typedef const TableIdentifier& const_reference;
63
 
  typedef TableIdentifier& reference;
64
 
 
65
 
  class Key
66
 
  {
67
 
    std::vector<char> key_buffer;
68
 
    size_t hash_value;
69
 
 
70
 
  public:
71
 
 
72
 
    Key() :
73
 
      hash_value(0)
74
 
    {
75
 
    }
76
 
 
77
 
    const char *vector() const
78
 
    {
79
 
      return &key_buffer[0];
80
 
    }
81
 
 
82
 
    std::vector<char> &vectorPtr()
83
 
    {
84
 
      return key_buffer;
85
 
    }
86
 
 
87
 
    void set(size_t resize_arg, const std::string &a, const std::string &b);
88
 
 
89
 
    friend bool operator==(const Key &left, const Key &right)
90
 
    {
91
 
      if (left.hash_value == right.hash_value and left.key_buffer.size() == right.key_buffer.size())
92
 
      {
93
 
        if (memcmp(&left.key_buffer[0], &right.key_buffer[0], left.key_buffer.size()) == 0)
94
 
          return true;
95
 
      }
96
 
 
97
 
      return false;
98
 
    }
99
 
 
100
 
    friend bool operator<(const Key &left, const Key &right)
101
 
    {
102
 
      return left.key_buffer < right.key_buffer;
103
 
    }
104
 
 
105
 
    size_t size() const
106
 
    {
107
 
      return key_buffer.size();
108
 
    }
109
 
 
110
 
    size_t getHashValue() const
111
 
    {
112
 
      return hash_value;
113
 
    }
114
 
  };
115
 
 
 
61
  typedef std::vector<char> Key;
116
62
private:
117
63
 
118
64
  Type type;
119
65
  std::string path;
120
66
  std::string table_name;
 
67
  std::string sql_path;
121
68
  Key key;
122
69
  size_t hash_value;
123
70
 
171
118
    return false;
172
119
  }
173
120
 
174
 
  static bool isView(message::Table::TableType arg) // Not a SQL view, but a view for I_S
175
 
  {
176
 
    switch (arg)
177
 
    {
178
 
    default:
179
 
    case message::Table::STANDARD:
180
 
    case message::Table::TEMPORARY:
181
 
    case message::Table::INTERNAL:
182
 
      break;
183
 
    case message::Table::FUNCTION:
184
 
      return true;
185
 
    }
186
 
 
187
 
    return false;
188
 
  }
189
 
 
190
121
  bool isView() const // Not a SQL view, but a view for I_S
191
122
  {
192
 
    return isView(type);
 
123
    if (type == message::Table::FUNCTION)
 
124
      return true;
 
125
    return false;
193
126
  }
194
127
 
195
128
  Type getType() const
197
130
    return type;
198
131
  }
199
132
 
200
 
  virtual void getSQLPath(std::string &sql_path) const;
 
133
  const std::string &getSQLPath();
201
134
 
202
 
  virtual const std::string &getPath() const;
 
135
  const std::string &getPath() const;
203
136
 
204
137
  void setPath(const std::string &new_path)
205
138
  {
213
146
 
214
147
  void copyToTableMessage(message::Table &message) const;
215
148
 
216
 
  friend bool operator<(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
 
149
  friend bool operator<(const TableIdentifier &left, const TableIdentifier &right)
217
150
  {
218
151
    if (left.getKey() < right.getKey())
219
152
    {
223
156
    return false;
224
157
  }
225
158
 
226
 
  friend std::ostream& operator<<(std::ostream& output, TableIdentifier::const_reference identifier)
 
159
  friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
227
160
  {
228
161
    const char *type_str;
229
162
 
258
191
    return output;  // for multiple << operators.
259
192
  }
260
193
 
261
 
  friend bool operator==(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
 
194
  friend bool operator==(TableIdentifier &left, TableIdentifier &right)
262
195
  {
263
 
    if (left.getHashValue() == right.getHashValue())
264
 
    {
265
 
      if (left.getKey() == right.getKey())
266
 
        return true;
267
 
    }
 
196
    if (left.getKey() == right.getKey())
 
197
      return true;
268
198
 
269
199
    return false;
270
200
  }
271
201
 
272
202
  static uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
273
 
  static size_t build_table_filename(std::string &path, const std::string &db, const std::string &table_name, bool is_tmp);
 
203
  static size_t build_table_filename(std::string &buff, const char *db, const char *table_name, bool is_tmp);
274
204
  static size_t build_tmptable_filename(std::string &buffer);
275
205
  static size_t build_tmptable_filename(std::vector<char> &buffer);
276
206
 
277
 
public:
278
 
  bool isValid() const;
 
207
  /*
 
208
    Create a table cache key
 
209
 
 
210
    SYNOPSIS
 
211
    createKey()
 
212
    key                 Create key here (must be of size MAX_DBKEY_LENGTH)
 
213
    table_list          Table definition
 
214
 
 
215
    IMPLEMENTATION
 
216
    The table cache_key is created from:
 
217
    db_name + \0
 
218
    table_name + \0
 
219
 
 
220
    if the table is a tmp table, we add the following to make each tmp table
 
221
    unique on the slave:
 
222
 
 
223
    4 bytes for master thread id
 
224
    4 bytes pseudo thread id
 
225
 
 
226
    RETURN
 
227
    Length of key
 
228
  */
 
229
  static uint32_t createKey(char *key, const char *db_arg, const char *table_name_arg)
 
230
  {
 
231
    uint32_t key_length;
 
232
    char *key_pos= key;
 
233
 
 
234
    key_pos= strcpy(key_pos, db_arg) + strlen(db_arg);
 
235
    key_pos= strcpy(key_pos+1, table_name_arg) +
 
236
      strlen(table_name_arg);
 
237
    key_length= (uint32_t)(key_pos-key)+1;
 
238
 
 
239
    return key_length;
 
240
  }
 
241
 
 
242
  static uint32_t createKey(char *key, const TableIdentifier &identifier)
 
243
  {
 
244
    uint32_t key_length;
 
245
    char *key_pos= key;
 
246
 
 
247
    key_pos= strcpy(key_pos, identifier.getSchemaName().c_str()) + identifier.getSchemaName().length();
 
248
    key_pos= strcpy(key_pos + 1, identifier.getTableName().c_str()) + identifier.getTableName().length();
 
249
    key_length= (uint32_t)(key_pos-key)+1;
 
250
 
 
251
    return key_length;
 
252
  }
279
253
 
280
254
  size_t getHashValue() const
281
255
  {
289
263
};
290
264
 
291
265
std::size_t hash_value(TableIdentifier const& b);
292
 
std::size_t hash_value(TableIdentifier::Key const& b);
 
266
 
 
267
typedef std::vector <TableIdentifier> TableIdentifiers;
293
268
 
294
269
} /* namespace drizzled */
295
270