Skip to content

Commit

Permalink
Fix Issue percona#4, part#2: make other members of class RDBSE_KEYDEF…
Browse files Browse the repository at this point in the history
… aware that unique keys do not have index extensions defined.

Also add suite/rocksdb/type_int_indexes.test
  • Loading branch information
spetrunia authored and jtolmer committed Jan 5, 2016
1 parent 865c49a commit 8f86ec6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 8 deletions.
36 changes: 28 additions & 8 deletions rdb_datadic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,23 +82,23 @@ void RDBSE_KEYDEF::setup(TABLE *tbl)

// "unique" secondary keys support:
bool unique_secondary_index= false;
uint loop_actual_key_parts= key_info->actual_key_parts;
m_key_parts= key_info->actual_key_parts;
if (keyno != tbl->s->primary_key && (key_info->flags & HA_NOSAME))
{
// From SQL layer's point of view, Unique secondary indexes do not
// have primary key columns at the end. Internally, they do.
loop_actual_key_parts += n_pk_key_parts;
m_key_parts += n_pk_key_parts;
unique_secondary_index= true;
}

size_t size= sizeof(Field_pack_info) * loop_actual_key_parts;
size_t size= sizeof(Field_pack_info) * m_key_parts;
pack_info= (Field_pack_info*)my_malloc(size, MYF(0));

uint len= INDEX_NUMBER_SIZE;
int unpack_len= 0;
KEY_PART_INFO *key_part= key_info->key_part;
/* this loop also loops over the 'extended key' tail */
for (uint i= 0; i < loop_actual_key_parts; i++)
for (uint i= 0; i < m_key_parts; i++)
{
Field *field= key_part->field;

Expand Down Expand Up @@ -213,6 +213,19 @@ void RDBSE_KEYDEF::successor(uchar *packed_tuple, uint len)
}
}

static Field *get_field_by_keynr(TABLE *tbl, KEY *key_info, uint part)
{
if (part < key_info->actual_key_parts)
{
return key_info->key_part[part].field;
}
else
{
uint pk= tbl->s->primary_key;
KEY *pk_info= &tbl->key_info[pk];
return pk_info->key_part[part - key_info->actual_key_parts].field;
}
}

/*
Get index columns from the record and pack them into mem-comparable form.
Expand Down Expand Up @@ -244,11 +257,17 @@ uint RDBSE_KEYDEF::pack_record(TABLE *tbl, const uchar *record,

// The following includes the 'extended key' tail:
if (n_key_parts == 0 || n_key_parts == MAX_REF_PARTS)
n_key_parts= key_info->actual_key_parts;
n_key_parts= m_key_parts;

for (uint i=0; i < n_key_parts; i++)
{
Field *field= key_info->key_part[i].field;
/*
Field *field= (i < key_info->actual_key_parts)?
key_info->key_part[i].field :
tbl->key_info[tbl->s->primary_key].key_part[i -
key_info->actual_key_parts].field;*/
Field *field= get_field_by_keynr(tbl, key_info, i);

my_ptrdiff_t ptr_diff= record - tbl->record[0];
field->move_field_offset(ptr_diff);

Expand Down Expand Up @@ -312,10 +331,11 @@ int RDBSE_KEYDEF::unpack_record(TABLE *table, uchar *buf,
if (unpack_info->size() != unpack_data_len)
return 1;

for (uint i= 0; i < key_info->actual_key_parts ; i++)
for (uint i= 0; i < m_key_parts ; i++)
{
Field *field= key_info->key_part[i].field;
Field_pack_info *fpi= &pack_info[i];
//Field *field= fpi->field;
Field *field= get_field_by_keynr(table, key_info, i);

if (fpi->unpack_func)
{
Expand Down
7 changes: 7 additions & 0 deletions rdb_datadic.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class RDBSE_KEYDEF
pk_key_parts(NULL),
pack_info(NULL),
keyno(keyno_arg),
m_key_parts(0),
maxlength(0) // means 'not intialized'
{
store_index_number(index_number_storage_form, indexnr_arg);
Expand Down Expand Up @@ -181,6 +182,12 @@ class RDBSE_KEYDEF

uint keyno; /* number of this index in the table */

/*
Number of key parts in the index (including "index extension"). This is how
many elemants are in the pack_info array.
*/
uint m_key_parts;

/*
Length of the mem-comparable form. In the encoding we're using, it is
constant (any value will have this length).
Expand Down

0 comments on commit 8f86ec6

Please sign in to comment.