1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
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.
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.
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
21
#ifndef DRIZZLED_KEY_H
22
#define DRIZZLED_KEY_H
26
#include "drizzled/memory/sql_alloc.h"
27
#include "drizzled/key_part_spec.h"
28
#include "drizzled/sql_list.h"
29
#include "drizzled/lex_string.h"
30
#include "drizzled/sql_string.h"
31
#include "drizzled/handler_structs.h"
35
namespace drizzled { namespace memory { class Root; } }
37
class Key :public drizzled::memory::SqlAlloc {
39
enum Keytype { PRIMARY, UNIQUE, MULTIPLE, FOREIGN_KEY};
41
KEY_CREATE_INFO key_create_info;
42
List<Key_part_spec> columns;
46
Key(enum Keytype type_par, const LEX_STRING &name_arg,
47
KEY_CREATE_INFO *key_info_arg,
48
bool generated_arg, List<Key_part_spec> &cols)
49
:type(type_par), key_create_info(*key_info_arg), columns(cols),
50
name(name_arg), generated(generated_arg)
52
Key(enum Keytype type_par, const char *name_arg, size_t name_len_arg,
53
KEY_CREATE_INFO *key_info_arg, bool generated_arg,
54
List<Key_part_spec> &cols)
55
:type(type_par), key_create_info(*key_info_arg), columns(cols),
56
generated(generated_arg)
58
name.str= const_cast<char *>(name_arg);
59
name.length= name_len_arg;
63
/* Equality comparison of keys (ignoring name) */
64
friend bool foreign_key_prefix(Key *a, Key *b);
68
int find_ref_key(KEY *key, uint32_t key_count, unsigned char *record, Field *field,
69
uint32_t *key_length, uint32_t *keypart);
71
Copy part of a record that forms a key or key prefix to a buffer.
73
The function takes a complete table record (as e.g. retrieved by
74
handler::index_read()), and a description of an index on the same table,
75
and extracts the first key_length bytes of the record which are part of a
76
key into to_key. If length == 0 then copy all bytes from the record that
79
@param to_key buffer that will be used as a key
80
@param from_record full record to be copied from
81
@param key_info descriptor of the index
82
@param key_length specifies length of all keyparts that will be copied
85
void key_copy(unsigned char *to_key, unsigned char *from_record, KEY *key_info, uint32_t key_length);
86
void key_copy(std::basic_string<unsigned char> &to_key,
87
unsigned char *from_record, KEY *key_info, uint32_t key_length);
88
void key_restore(unsigned char *to_record, unsigned char *from_key, KEY *key_info,
90
void key_zero_nulls(unsigned char *tuple, KEY *key_info);
91
bool key_cmp_if_same(Table *form,const unsigned char *key,uint32_t index,uint32_t key_length);
92
void key_unpack(String *to,Table *form,uint32_t index);
93
bool is_key_used(Table *table, uint32_t idx, const MyBitmap *fields);
94
int key_cmp(KEY_PART_INFO *key_part, const unsigned char *key, uint32_t key_length);
95
extern "C" int key_rec_cmp(void *key_info, unsigned char *a, unsigned char *b);
96
#endif /* DRIZZLED_KEY_H */