264
264
ha_statistic_increment(&SSV::ha_read_rnd_next_count);
266
/* Unpack and copy the current row to Drizzle's result buffer */
266
/* Unpack and copy the current row to Drizzle's result buffer. */
267
267
unpack_row(drizzle_buf, current_row, current_row_length);
269
/* Retrieve both key and row of the next record with one allocation */
269
/* Retrieve both key and row of the next record with one allocation. */
270
270
next_key = share->dict.next_key_and_row(current_key, current_key_length,
271
271
&next_key_length, &next_row,
272
272
&next_row_length);
400
400
int ha_blitz::index_read_idx(unsigned char *buf, uint32_t key_num,
401
401
const unsigned char *key, uint32_t key_len,
402
402
enum ha_rkey_function /*find_flag*/) {
406
403
/* A PK in BlitzDB is the 'actual' key in the data dictionary.
407
404
Therefore we do a direct lookup on the data dictionary. All
408
405
other indexes are clustered btree. */
409
406
if (key_num == table->s->primary_key) {
410
fetched_row = share->dict.get_row((const char *)key, key_len, &fetched_len);
407
char *pk, *fetched_row;
408
int fetched_len, blitz_key_len;
410
pk = native_to_blitz_key(key, key_num, &blitz_key_len);
412
fprintf(stderr, "blitz_key_len in index_read_idx: %d\n", blitz_key_len);
414
fetched_row = share->dict.get_row((const char *)pk, blitz_key_len,
412
417
if (fetched_row == NULL)
413
418
return HA_ERR_KEY_NOT_FOUND;
415
/* Found the row. Copy it to drizzle's result buffer. TODO: Memory copy
416
operation SUCKS. Find a way to make TC use this buffer directly. */
417
memcpy(buf, fetched_row, fetched_len);
420
/* Found the row. Unpack it into Drizzle's buffer */
421
unpack_row(buf, fetched_row, fetched_len);
418
422
free(fetched_row);
420
424
/* Now keep track of the key. This is because another function that
421
425
needs this information such as delete_row() might be called before
422
BlitzDB reaches index_end() */
426
BlitzDB reaches index_end(). */
423
427
memcpy(key_buffer, key, key_len);
424
428
updateable_key = key_buffer;
425
429
updateable_key_length = key_len;
625
629
unsigned char *pos = (unsigned char *)pack_to;
631
memset(pack_to, 0, BLITZ_MAX_KEY_LENGTH);
627
633
/* Loop through key part(s) and pack them. Don't worry about NULL key
628
634
values since this functionality is currently disabled in BlitzDB.*/
629
635
for (; key_part != key_part_end; key_part++) {
635
641
return packed_length;
644
/* Converts a native Drizzle index key to BlitzDB's format. */
645
char *ha_blitz::native_to_blitz_key(const unsigned char *native_key,
646
const int key_num, int *return_key_len) {
647
KEY *key = &table->key_info[key_num];
648
KEY_PART_INFO *key_part = key->key_part;
649
KEY_PART_INFO *key_part_end = key_part + key->key_parts;
650
int total_key_len = 0;
652
unsigned char *key_pos = (unsigned char *)native_key;
653
unsigned char *keybuf_pos = (unsigned char *)this->key_buffer;
655
memset(key_buffer, 0, BLITZ_MAX_KEY_LENGTH);
657
for (; key_part != key_part_end; key_part++) {
658
key_part->field->pack(keybuf_pos, key_pos);
660
key_pos += key_part->field->key_length();
661
keybuf_pos += key_part->field->pack_length();
662
total_key_len += key_part->field->pack_length();
665
*return_key_len = total_key_len;
666
return this->key_buffer;
638
669
size_t ha_blitz::pack_row(unsigned char *row_buffer,
639
670
unsigned char *row_to_pack) {
640
671
unsigned char *pos;
674
705
memcpy(to, pos, table->s->null_bytes);
675
706
pos += table->s->null_bytes;
677
/* Unpack all fields in the provided row */
708
/* Unpack all fields in the provided row. */
678
709
for (Field **field = table->field; *field; field++) {
679
710
if (!((*field)->is_null())) {
680
711
pos = (*field)->unpack(to + (*field)->offset(table->record[0]), pos);