Skip to content
Snippets Groups Projects
Commit d1e7ee51 authored by Roman Tsisyk's avatar Roman Tsisyk Committed by Roman Tsisyk
Browse files

tuple: extract field_def from tuple_format

No semantic changes.

Needed for #2754
parent 5554f25e
No related branches found
No related tags found
No related merge requests found
......@@ -31,6 +31,8 @@
* SUCH DAMAGE.
*/
#include <stdint.h>
#if defined(__cplusplus)
extern "C" {
#endif /* defined(__cplusplus) */
......@@ -61,6 +63,34 @@ extern const char *field_type_strs[];
enum field_type
field_type_by_name(const char *name);
/**
* @brief Field definition
* Contains information about of one tuple field.
*/
struct field_def {
/**
* Field type of an indexed field.
* If a field participates in at least one of space indexes
* then its type is stored in this member.
* If a field does not participate in an index
* then UNKNOWN is stored for it.
*/
enum field_type type;
/**
* Offset slot in field map in tuple. Normally tuple
* stores field map - offsets of all fields participating
* in indexes. This allows quick access to most used
* fields without parsing entire mspack. This member
* stores position in the field map of tuple for current
* field. If the field does not participate in indexes
* then it has no offset in field map and INT_MAX is
* stored in this member. Due to specific field map in
* tuple (it is stored before tuple), the positions in
* field map is negative.
*/
int32_t offset_slot;
};
#if defined(__cplusplus)
} /* extern "C" */
#endif /* defined(__cplusplus) */
......
......@@ -63,7 +63,7 @@ tuple_format_create(struct tuple_format *format, struct key_def **keys,
for (; part < parts_end; part++) {
assert(part->fieldno < format->field_count);
struct tuple_field_format *field =
struct field_def *field =
&format->fields[part->fieldno];
if (field->type == FIELD_TYPE_ANY) {
......@@ -168,7 +168,7 @@ tuple_format_alloc(struct key_def **keys, uint16_t key_count)
uint32_t field_count = key_count > 0 ? max_fieldno + 1 : 0;
uint32_t total = sizeof(struct tuple_format) +
field_count * sizeof(struct tuple_field_format);
field_count * sizeof(struct field_def);
struct tuple_format *format = (struct tuple_format *) malloc(total);
if (format == NULL) {
......@@ -215,7 +215,7 @@ struct tuple_format *
tuple_format_dup(const struct tuple_format *src)
{
uint32_t total = sizeof(struct tuple_format) +
src->field_count * sizeof(struct tuple_field_format);
src->field_count * sizeof(struct field_def);
struct tuple_format *format = (struct tuple_format *) malloc(total);
if (format == NULL) {
......
......@@ -31,7 +31,8 @@
* SUCH DAMAGE.
*/
#include "key_def.h" /* for enum field_type */
#include "key_def.h"
#include "field_def.h"
#include "errinj.h"
#if defined(__cplusplus)
......@@ -60,38 +61,6 @@ enum { TUPLE_INDEX_BASE = 1 };
*/
enum { TUPLE_OFFSET_SLOT_NIL = INT32_MAX };
/**
* @brief Tuple field format
* Support structure for struct tuple_format.
* Contains information of one field.
*/
struct tuple_field_format {
/**
* Field type of an indexed field.
* If a field participates in at least one of space indexes
* then its type is stored in this member.
* If a field does not participate in an index
* then UNKNOWN is stored for it.
*/
enum field_type type;
/**
* Offset slot in field map in tuple.
* Normally tuple stores field map - offsets of all fields
* participating in indexes. This allows quick access to most
* used fields without parsing entire mspack.
* This member stores position in the field map of tuple
* for current field.
* If the field does not participate in indexes then it has
* no offset in field map and INT_MAX is stored in this member.
* Due to specific field map in tuple (it is stored before tuple),
* the positions in field map is negative.
* Thus if this member is negative, smth like
* tuple->data[((uint32_t *)tuple)[format->offset_slot[fieldno]]]
* gives the start of the field
*/
int32_t offset_slot;
};
struct tuple;
struct tuple_format;
......@@ -132,7 +101,7 @@ struct tuple_format {
/* Length of 'fields' array. */
uint32_t field_count;
/* Formats of the fields */
struct tuple_field_format fields[];
struct field_def fields[0];
};
extern struct tuple_format **tuple_formats;
......
......@@ -397,7 +397,7 @@ vy_stmt_new_surrogate_from_key(const char *key, enum iproto_type type,
char *raw = (char *) tuple_data(stmt);
char *wpos = mp_encode_array(raw, field_count);
for (uint32_t i = 0; i < field_count; ++i) {
struct tuple_field_format *field = &format->fields[i];
struct field_def *field = &format->fields[i];
if (field->type == FIELD_TYPE_ANY) {
wpos = mp_encode_nil(wpos);
continue;
......@@ -450,7 +450,7 @@ vy_stmt_new_surrogate(struct tuple_format *format, const struct tuple *src,
(void) src_count;
char *pos = mp_encode_array(data, format->field_count);
for (uint32_t i = 0; i < format->field_count; ++i) {
struct tuple_field_format *field = &format->fields[i];
struct field_def *field = &format->fields[i];
if (field->type == FIELD_TYPE_ANY) {
/* Unindexed field - write NIL */
pos = mp_encode_nil(pos);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment