~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/plugin/info_schema_table.h

  • Committer: Brian Aker
  • Date: 2009-11-30 19:13:19 UTC
  • mfrom: (1225.1.39 figure)
  • Revision ID: brian@gaz-20091130191319-zyt51fidacic3brf
Merge Padraig

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#ifndef DRIZZLED_PLUGIN_INFO_SCHEMA_TABLE_H
22
22
#define DRIZZLED_PLUGIN_INFO_SCHEMA_TABLE_H
23
23
 
 
24
#include "drizzled/hash/crc32.h"
 
25
 
24
26
#include <string>
25
27
#include <set>
26
28
#include <algorithm>
53
55
             enum enum_field_types in_type,
54
56
             int32_t in_value,
55
57
             uint32_t in_flags,
56
 
             const std::string& in_old_name,
57
 
             uint32_t in_open_method)
 
58
             const std::string& in_old_name)
58
59
    :
59
60
      name(in_name),
60
61
      length(in_length),
61
62
      type(in_type),
62
63
      value(in_value),
63
64
      flags(in_flags),
64
 
      old_name(in_old_name),
65
 
      open_method(in_open_method)
 
65
      old_name(in_old_name)
66
66
  {}
67
67
 
68
68
  ColumnInfo()
71
71
      length(0),
72
72
      type(DRIZZLE_TYPE_VARCHAR),
73
73
      flags(0),
74
 
      old_name(),
75
 
      open_method(SKIP_OPEN_TABLE)
 
74
      old_name()
76
75
  {}
77
76
 
78
77
  /**
99
98
  }
100
99
 
101
100
  /**
102
 
   * @return the open method for this column.
103
 
   */
104
 
  uint32_t getOpenMethod() const
105
 
  {
106
 
    return open_method;
107
 
  }
108
 
 
109
 
  /**
110
101
   * @return the flags for this column.
111
102
   */
112
103
  uint32_t getFlags() const
176
167
   */
177
168
  const std::string old_name;
178
169
 
179
 
  /**
180
 
   * This should be one of @c SKIP_OPEN_TABLE,
181
 
   * @c OPEN_FRM_ONLY or @c OPEN_FULL_TABLE.
182
 
   */
183
 
  uint32_t open_method;
184
 
 
185
170
};
186
171
 
187
172
/**
194
179
public:
195
180
  virtual ~InfoSchemaMethods() {}
196
181
 
197
 
  virtual Table *createSchemaTable(Session *session,
198
 
                                   TableList *table_list) const;
199
182
  virtual int fillTable(Session *session, 
200
 
                        TableList *tables);
201
 
  virtual int processTable(Session *session, TableList *tables,
 
183
                        Table *table,
 
184
                        InfoSchemaTable *schema_table);
 
185
  virtual int processTable(InfoSchemaTable *store_table, 
 
186
                           Session *session, TableList *tables,
202
187
                           Table *table, bool res, LEX_STRING *db_name,
203
 
                           LEX_STRING *table_name) const;
 
188
                           LEX_STRING *table_name);
204
189
  virtual int oldFormat(Session *session, 
205
190
                        InfoSchemaTable *schema_table) const;
206
191
};
215
200
  InfoSchemaRecord()
216
201
    :
217
202
      record(NULL),
218
 
      rec_len(0)
 
203
      rec_len(0),
 
204
      checksum(0)
219
205
  {}
220
206
 
221
207
  InfoSchemaRecord(unsigned char *buf,
222
208
                   size_t in_len)
223
209
    :
224
 
      record(buf),
225
 
      rec_len(in_len)
226
 
  {}
 
210
      record(NULL),
 
211
      rec_len(in_len),
 
212
      checksum(0)
 
213
  {
 
214
    record= new unsigned char[rec_len];
 
215
    memcpy(record, buf, rec_len);
 
216
    checksum= drizzled::hash::crc32((const char *) record, rec_len);
 
217
  }
227
218
 
228
219
  InfoSchemaRecord(const InfoSchemaRecord &rhs)
229
220
    :
232
223
  {
233
224
    record= new(std::nothrow) unsigned char[rec_len];
234
225
    memcpy(record, rhs.record, rec_len);
 
226
    checksum= drizzled::hash::crc32((const char *) record, rec_len);
235
227
  }
236
228
 
237
229
  ~InfoSchemaRecord()
242
234
    }
243
235
  }
244
236
 
 
237
  /**
 
238
   * Copy this record into the memory passed to this function.
 
239
   *
 
240
   * @param[out] buf copy the record into this memory
 
241
   */
245
242
  void copyRecordInto(unsigned char *buf)
246
243
  {
247
244
    memcpy(buf, record, rec_len);
248
245
  }
249
246
 
 
247
  /**
 
248
   * @return the length of this record
 
249
   */
 
250
  size_t getRecordLength() const
 
251
  {
 
252
    return rec_len;
 
253
  }
 
254
 
 
255
  /**
 
256
   * @return the checksum of the data in this record
 
257
   */
 
258
  uint32_t getChecksum() const
 
259
  {
 
260
    return checksum;
 
261
  }
 
262
 
 
263
  /**
 
264
   * @param[in] crc a checksum to compare
 
265
   * @return true if the input checksum matches the checksum for this record; false otherwise
 
266
   */
 
267
  bool checksumMatches(uint32_t crc) const
 
268
  {
 
269
    return (checksum == crc);
 
270
  }
 
271
 
250
272
private:
251
273
 
252
274
  unsigned char *record;
253
275
 
254
276
  size_t rec_len;
255
277
 
 
278
  uint32_t checksum;
 
279
 
256
280
};
257
281
 
258
282
class DeleteRows
265
289
  }
266
290
};
267
291
 
 
292
class FindRowByChecksum
 
293
{
 
294
  uint32_t cs;
 
295
public:
 
296
  FindRowByChecksum(uint32_t in_cs)
 
297
    :
 
298
      cs(in_cs)
 
299
  {}
 
300
 
 
301
  inline bool operator()(const InfoSchemaRecord *rec) const
 
302
  {
 
303
    return (cs == rec->getChecksum());
 
304
  }
 
305
};
 
306
 
268
307
/**
269
308
 * @class InfoSchemaTable
270
309
 * @brief 
331
370
  }
332
371
 
333
372
  /**
334
 
   * Create the temporary I_S tables using schema_table data.
335
 
   *
336
 
   * @param[in] session a session handler
337
 
   * @param[in] table_list Used to pass I_S table information (fields,
338
 
   *                       tables, parameters, etc.) and table name
339
 
   * @retval \# pointer to created table
340
 
   * @retval NULL Can't create table
341
 
   */
342
 
  Table *createSchemaTable(Session *session, TableList *table_list) const
343
 
  {
344
 
    Table *retval= i_s_methods->createSchemaTable(session, table_list);
345
 
    return retval;
346
 
  }
347
 
 
348
 
  /**
349
373
   * Fill I_S table.
350
374
   *
351
375
   * @param[in] session a session handler
352
 
   * @param[in] tables I_S table
353
376
   * @return 0 on success; 1 on error
354
377
   */
355
 
  int fillTable(Session *session, TableList *tables)
 
378
  int fillTable(Session *session, Table *table)
356
379
  {
357
 
    int retval= i_s_methods->fillTable(session, tables);
 
380
    int retval= i_s_methods->fillTable(session, table, this);
358
381
    return retval;
359
382
  }
360
383
 
371
394
   * @return 0 on success; 1 on error
372
395
   */
373
396
  int processTable(Session *session, TableList *tables, Table *table,
374
 
                   bool res, LEX_STRING *db_name, LEX_STRING *tab_name) const
 
397
                   bool res, LEX_STRING *db_name, LEX_STRING *tab_name)
375
398
  {
376
 
    int retval= i_s_methods->processTable(session, tables, table,
 
399
    int retval= i_s_methods->processTable(this, session, tables, table,
377
400
                                          res, db_name, tab_name);
378
401
    return retval;
379
402
  }
483
506
    return column_info;
484
507
  }
485
508
 
 
509
  /**
 
510
   * @return the rows for this I_S table.
 
511
   */
486
512
  Rows &getRows()
487
513
  {
488
514
    return rows;
489
515
  }
490
516
 
 
517
  /**
 
518
   * Clear the rows for this table and de-allocate all memory for this rows.
 
519
   */
491
520
  void clearRows()
492
521
  {
493
522
    std::for_each(rows.begin(),
496
525
    rows.clear();
497
526
  }
498
527
 
 
528
  /**
 
529
   * Add a row to the std::vector of rows for this I_S table. For the moment, we check to make sure
 
530
   * that we do not add any duplicate rows. This is done in a niave manner for the moment by
 
531
   * checking the crc of the raw data for each row. We will not add this row to the std::vector of
 
532
   * rows for this I_S table is a duplicate row already exists in the std::vector.
 
533
   *
 
534
   * @param[in] buf raw data for the record to add
 
535
   * @param[in] len size of the raw data for the record to add
 
536
   */
499
537
  void addRow(unsigned char *buf, size_t len)
500
538
  {
501
 
    InfoSchemaRecord *record= new InfoSchemaRecord(buf, len);
502
 
    rows.push_back(record);
 
539
    uint32_t cs= drizzled::hash::crc32((const char *) buf, len);
 
540
    Rows::iterator it= std::find_if(rows.begin(),
 
541
                                    rows.end(),
 
542
                                    FindRowByChecksum(cs));
 
543
    if (it == rows.end())
 
544
    {
 
545
      InfoSchemaRecord *record= new InfoSchemaRecord(buf, len);
 
546
      rows.push_back(record);
 
547
    }
503
548
  }
504
549
 
505
550
  /**
511
556
    return column_info[index]->getName();
512
557
  }
513
558
 
514
 
  /**
515
 
   * @param[in] index the index of this column
516
 
   * @return the open method for the column at the given index
517
 
   */
518
 
  uint32_t getColumnOpenMethod(int index) const
519
 
  {
520
 
    return column_info[index]->getOpenMethod();
521
 
  }
522
 
 
523
559
private:
524
560
 
525
561
  /**
556
592
   */
557
593
  Columns column_info;
558
594
 
 
595
  /**
 
596
   * The rows for this I_S table.
 
597
   */
559
598
  Rows rows;
560
599
 
561
600
  /**