~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/key.h

  • Committer: Brian Aker
  • Date: 2009-11-18 06:24:48 UTC
  • mfrom: (1220.1.15 staging)
  • Revision ID: brian@gaz-20091118062448-o36lo3yv81sc6u9z
Merge Brian + Stewart

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2008 Sun Microsystems, Inc.
 
4
 *  Copyright (C) 2008 Sun Microsystems
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
21
21
#ifndef DRIZZLED_KEY_H
22
22
#define DRIZZLED_KEY_H
23
23
 
24
 
#include <string>
25
 
#include <boost/dynamic_bitset.hpp>
26
 
 
27
 
#include "drizzled/memory/sql_alloc.h"
28
 
#include "drizzled/key_part_spec.h"
29
 
#include "drizzled/sql_list.h"
30
 
#include "drizzled/lex_string.h"
31
 
#include "drizzled/sql_string.h"
32
 
#include "drizzled/handler_structs.h"
33
 
 
34
 
namespace drizzled
35
 
{
36
 
 
37
 
namespace memory { class Root; }
 
24
 
 
25
#include <drizzled/sql_alloc.h>
 
26
#include <drizzled/key_part_spec.h>
 
27
#include <drizzled/sql_list.h>
 
28
#include <drizzled/lex_string.h>
 
29
#include <drizzled/handler_structs.h>
38
30
 
39
31
class Item;
 
32
typedef struct st_mem_root MEM_ROOT;
40
33
 
41
 
class Key :public memory::SqlAlloc {
 
34
class Key :public Sql_alloc {
42
35
public:
43
36
  enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY};
44
 
  Keytype type;
 
37
  enum Keytype type;
45
38
  KEY_CREATE_INFO key_create_info;
46
39
  List<Key_part_spec> columns;
47
40
  LEX_STRING name;
48
41
  bool generated;
49
42
 
50
 
  Key(Keytype type_par,
51
 
      const lex_string_t &name_arg,
 
43
  Key(enum Keytype type_par, const LEX_STRING &name_arg,
52
44
      KEY_CREATE_INFO *key_info_arg,
53
 
      bool generated_arg, List<Key_part_spec> &cols) :
54
 
    type(type_par),
55
 
    key_create_info(*key_info_arg),
56
 
    columns(cols),
57
 
    name(name_arg),
58
 
    generated(generated_arg)
 
45
      bool generated_arg, List<Key_part_spec> &cols)
 
46
    :type(type_par), key_create_info(*key_info_arg), columns(cols),
 
47
    name(name_arg), generated(generated_arg)
59
48
  {}
60
 
 
61
 
  Key(Keytype type_par,
62
 
      const char *name_arg,
63
 
      size_t name_len_arg,
64
 
      KEY_CREATE_INFO *key_info_arg,
65
 
      bool generated_arg,
66
 
      List<Key_part_spec> &cols) :
67
 
    type(type_par),
68
 
    key_create_info(*key_info_arg),
69
 
    columns(cols),
 
49
  Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
 
50
      KEY_CREATE_INFO *key_info_arg, bool generated_arg,
 
51
      List<Key_part_spec> &cols)
 
52
    :type(type_par), key_create_info(*key_info_arg), columns(cols),
70
53
    generated(generated_arg)
71
54
  {
72
 
    name.str= const_cast<char *>(name_arg);
 
55
    name.str= (char *)name_arg;
73
56
    name.length= name_len_arg;
74
57
  }
75
58
 
 
59
  /**
 
60
   * Construct an (almost) deep copy of this key. Only those
 
61
   * elements that are known to never change are not copied.
 
62
   * If out of memory, a partial copy is returned and an error is set
 
63
   * in Session.
 
64
   */
 
65
  Key(const Key &rhs, MEM_ROOT *mem_root);
76
66
  virtual ~Key() {}
77
67
  /* Equality comparison of keys (ignoring name) */
78
68
  friend bool foreign_key_prefix(Key *a, Key *b);
 
69
  /**
 
70
    Used to make a clone of this object for ALTER/CREATE TABLE
 
71
    @sa comment for Key_part_spec::clone
 
72
  */
 
73
  virtual Key *clone(MEM_ROOT *mem_root) const
 
74
    { return new (mem_root) Key(*this, mem_root); }
79
75
};
80
76
 
81
77
 
82
 
int find_ref_key(KeyInfo *key, uint32_t key_count, unsigned char *record, Field *field,
 
78
int find_ref_key(KEY *key, uint32_t key_count, unsigned char *record, Field *field,
83
79
                 uint32_t *key_length, uint32_t *keypart);
84
80
/**
85
81
  Copy part of a record that forms a key or key prefix to a buffer.
96
92
  @param key_length  specifies length of all keyparts that will be copied
97
93
*/
98
94
 
99
 
DRIZZLED_API void key_copy(unsigned char *to_key, unsigned char *from_record, KeyInfo *key_info, uint32_t key_length);
 
95
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info, uint32_t key_length);
100
96
void key_copy(std::basic_string<unsigned char> &to_key,
101
 
              unsigned char *from_record, KeyInfo *key_info, uint32_t key_length);
102
 
void key_restore(unsigned char *to_record, unsigned char *from_key, KeyInfo *key_info,
 
97
              unsigned char *from_record, KEY *key_info, uint32_t key_length);
 
98
void key_restore(unsigned char *to_record, unsigned char *from_key, KEY *key_info,
103
99
                 uint16_t key_length);
104
 
void key_zero_nulls(unsigned char *tuple, KeyInfo *key_info);
 
100
void key_zero_nulls(unsigned char *tuple, KEY *key_info);
105
101
bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
106
 
void key_unpack(String *to, const Table *form,uint32_t index);
107
 
bool is_key_used(Table *table, uint32_t idx, const boost::dynamic_bitset<>& fields);
108
 
int key_cmp(KeyPartInfo *key_part, const unsigned char *key, uint32_t key_length);
109
 
 
110
 
} /* namespace drizzled */
111
 
 
 
102
void key_unpack(String *to,Table *form,uint32_t index);
 
103
bool is_key_used(Table *table, uint32_t idx, const MyBitmap *fields);
 
104
int key_cmp(KEY_PART_INFO *key_part, const unsigned char *key, uint32_t key_length);
 
105
extern "C" int key_rec_cmp(void *key_info, unsigned char *a, unsigned char *b);
112
106
#endif /* DRIZZLED_KEY_H */