MySQL 9.1.0
Source Code Documentation
|
#include <assert.h>
#include <stddef.h>
#include <sys/types.h>
#include "lex_string.h"
#include "my_base.h"
#include "my_inttypes.h"
#include "sql/key_spec.h"
#include "sql/sql_plugin_ref.h"
Go to the source code of this file.
Classes | |
class | FOREIGN_KEY |
class | KEY_PART_INFO |
class | KEY |
Macros | |
#define | REC_PER_KEY_UNKNOWN -1.0f |
If an entry for a key part in KEY::rec_per_key_float[] has this value, then the storage engine has not provided a value for it and the rec_per_key value for this key part is unknown. More... | |
#define | IN_MEMORY_ESTIMATE_UNKNOWN -1.0 |
If the "in memory estimate" for a table (in ha_statistics.table_in_mem_estimate) or index (in KEY::m_in_memory_estimate) is not known or not set by the storage engine, then it should have the following value. More... | |
Typedefs | |
typedef float | rec_per_key_t |
Data type for records per key estimates that are stored in the KEY::rec_per_key_float[] array. More... | |
Functions | |
int | find_ref_key (KEY *key, uint key_count, uchar *record, Field *field, uint *key_length, uint *keypart) |
void | key_copy (uchar *to_key, const uchar *from_record, const KEY *key_info, uint key_length) |
Copy part of a record that forms a key or key prefix to a buffer. More... | |
void | key_restore (uchar *to_record, const uchar *from_key, const KEY *key_info, uint key_length) |
Restore a key from some buffer to record. More... | |
bool | key_cmp_if_same (const TABLE *table, const uchar *key, uint index, uint key_length) |
Compare if a key has changed. More... | |
void | key_unpack (String *to, TABLE *table, KEY *key) |
void | field_unpack (String *to, Field *field, uint max_length, bool prefix_key) |
Unpack a field and append it. More... | |
bool | is_key_used (TABLE *table, uint idx, const MY_BITMAP *fields) |
int | key_cmp (KEY_PART_INFO *key_part, const uchar *key, uint key_length) |
Compare key in record buffer to a given key. More... | |
int | key_cmp2 (KEY_PART_INFO *key_part, const uchar *key1, uint key1_length, const uchar *key2, uint key2_length) |
Compare two given keys. More... | |
int | key_rec_cmp (KEY **key_info, uchar *a, uchar *b) |
Compare two records in index order. More... | |
#define IN_MEMORY_ESTIMATE_UNKNOWN -1.0 |
If the "in memory estimate" for a table (in ha_statistics.table_in_mem_estimate) or index (in KEY::m_in_memory_estimate) is not known or not set by the storage engine, then it should have the following value.
#define REC_PER_KEY_UNKNOWN -1.0f |
If an entry for a key part in KEY::rec_per_key_float[] has this value, then the storage engine has not provided a value for it and the rec_per_key value for this key part is unknown.
typedef float rec_per_key_t |
Data type for records per key estimates that are stored in the KEY::rec_per_key_float[] array.
Unpack a field and append it.
[in,out] | to | String to append the field contents to. |
field | Field to unpack. | |
max_length | Maximum length of field to unpack or 0 for unlimited. | |
prefix_key | The field is used as a prefix key. |
int find_ref_key | ( | KEY * | key, |
uint | key_count, | ||
uchar * | record, | ||
Field * | field, | ||
uint * | key_length, | ||
uint * | keypart | ||
) |
int key_cmp | ( | KEY_PART_INFO * | key_part, |
const uchar * | key, | ||
uint | key_length | ||
) |
Compare key in record buffer to a given key.
key_part | Key part handler |
key | Key to compare to value in table->record[0] |
key_length | length of 'key' |
The function compares given key and key in record buffer, part by part, using info from key_part arg. Since callers expect before/after rather than lesser/greater, result depends on the HA_REVERSE_SORT flag of the key part. E.g. For ASC key part and two keys, 'A' and 'Z', -1 will be returned. For same keys, but DESC key part, 1 will be returned.
int key_cmp2 | ( | KEY_PART_INFO * | key_part, |
const uchar * | key1, | ||
uint | key1_length, | ||
const uchar * | key2, | ||
uint | key2_length | ||
) |
Compare two given keys.
key_part | Key part handler |
key1 | Key to be compared with key2 |
key1_length | length of 'key1' |
key2 | Key to be compared with key1 |
key2_length | length of 'key2' |
Below comparison code is under the assumption that key1_length and key2_length are same and key1_length, key2_length are non zero value.
Compare if a key has changed.
table | TABLE |
key | key to compare to row |
idx | Index used |
key_length | Length of key |
0 | If key is equal |
1 | Key has changed |
Copy part of a record that forms a key or key prefix to a buffer.
The function takes a complete table record (as e.g. retrieved by handler::index_read()), and a description of an index on the same table, and extracts the first key_length bytes of the record which are part of a key into to_key. If length == 0 then copy all bytes from the record that form a key.
to_key | buffer that will be used as a key |
from_record | full record to be copied from |
key_info | descriptor of the index |
key_length | specifies length of all keyparts that will be copied |
Compare two records in index order.
This method is set-up such that it can be called directly from the priority queue and it is attempted to be optimised as much as possible since this will be called O(N * log N) times while performing a merge sort in various places in the code.
We retrieve the pointer to table->record[0] using the fact that key_parts have an offset making it possible to calculate the start of the record. We need to get the diff to the compared record since none of the records being compared are stored in table->record[0].
We first check for NULL values, if there are no NULL values we use a compare method that gets two field pointers and a max length and return the result of the comparison.
key is a null terminated array, since in some cases (clustered primary key) it must compare more than one index. We only compare the fields that are specified in table->read_set and stop at the first non set field. The first must be set!
key | Null terminated array of index information |
first_rec | Pointer to record compare with |
second_rec | Pointer to record compare against first_rec |
0 | Keys are equal |
-1 | second_rec is after first_rec |
+1 | first_rec is after second_rec |
void key_restore | ( | uchar * | to_record, |
const uchar * | from_key, | ||
const KEY * | key_info, | ||
uint | key_length | ||
) |
Restore a key from some buffer to record.
This function converts a key into record format. It can be used in cases when we want to return a key as a result row.
to_record | record buffer where the key will be restored to |
from_key | buffer that contains a key |
key_info | descriptor of the index |
key_length | specifies length of all keyparts that will be restored |