@@ -711,7 +711,7 @@ class Primary_key_comparator : public rocksdb::Comparator
711
711
712
712
/* The following is not needed by RocksDB, but conceptually should be here: */
713
713
static ulong get_hashnr (const char *key, size_t key_len);
714
- const char * Name () const { return " RocksDB_SE_v3.1 " ; }
714
+ const char * Name () const { return " RocksDB_SE_v3.2 " ; }
715
715
716
716
// TODO: advanced funcs:
717
717
// - FindShortestSeparator
@@ -728,7 +728,7 @@ class Reverse_comparator : public rocksdb::Comparator
728
728
{
729
729
return -bytewise_compare (a,b);
730
730
}
731
- const char * Name () const { return " rev:RocksDB_SE_v3.1 " ; }
731
+ const char * Name () const { return " rev:RocksDB_SE_v3.2 " ; }
732
732
void FindShortestSeparator (std::string* start, const rocksdb::Slice& limit) const {}
733
733
void FindShortSuccessor (std::string* key) const {}
734
734
};
@@ -1556,6 +1556,10 @@ void ha_rocksdb::convert_record_to_storage_format(rocksdb::Slice *packed_rec)
1556
1556
1557
1557
for (uint i=0 ; i < table->s ->fields ; i++)
1558
1558
{
1559
+ /* Don't pack decode-able PK key parts */
1560
+ if (field_enc[i].skip )
1561
+ continue ;
1562
+
1559
1563
Field *field= table->field [i];
1560
1564
if (field_enc[i].maybe_null ())
1561
1565
{
@@ -1624,7 +1628,9 @@ int ha_rocksdb::convert_record_from_storage_format(rocksdb::Slice *slice,
1624
1628
1625
1629
/*
1626
1630
Unpack the record in this->retrieved_record from storage format into
1627
- buf (which can be table->record[0] or table->record[1])
1631
+ buf (which can be table->record[0] or table->record[1]).
1632
+
1633
+ psergey-todo: this->last_rowkey has a part of the data.
1628
1634
1629
1635
If the table has blobs, the unpacked data in buf may keep pointers to the
1630
1636
data in this->retrieved_record.
@@ -1639,12 +1645,26 @@ int ha_rocksdb::convert_record_from_storage_format(uchar * buf)
1639
1645
Stream_reader reader (retrieved_record);
1640
1646
my_ptrdiff_t ptr_diff= buf - table->record [0 ];
1641
1647
1642
- const char *null_bytes;
1643
- if (!(null_bytes= reader.read (null_bytes_in_rec)))
1648
+ /*
1649
+ Decode PK fields from the key
1650
+ */
1651
+ rocksdb::Slice rowkey_slice (last_rowkey.ptr (), last_rowkey.length ());
1652
+
1653
+ DBUG_ASSERT (pk_descr->get_unpack_data_len () == 0 );
1654
+ rocksdb::Slice pk_unpack_info_slice;
1655
+ if (pk_descr->unpack_record (table, buf, &rowkey_slice, &pk_unpack_info_slice))
1656
+ return HA_ERR_INTERNAL_ERROR;
1657
+
1658
+ /* Other fields are decoded from the value */
1659
+ const char * UNINIT_VAR (null_bytes);
1660
+ if (null_bytes_in_rec && !(null_bytes= reader.read (null_bytes_in_rec)))
1644
1661
return HA_ERR_INTERNAL_ERROR;
1645
1662
1646
1663
for (uint i=0 ; i < table->s ->fields ; i++)
1647
1664
{
1665
+ if (field_enc[i].skip )
1666
+ continue ;
1667
+
1648
1668
Field *field= table->field [i];
1649
1669
1650
1670
int isNull = field_enc[i].maybe_null () &&
@@ -1765,6 +1785,29 @@ void ha_rocksdb::setup_field_converters()
1765
1785
for (i= 0 ; i < table->s ->fields ; i++)
1766
1786
{
1767
1787
Field *field= table->field [i];
1788
+ field_enc[i].skip = false ;
1789
+
1790
+ /*
1791
+ Check if this field is
1792
+ - a part of primary key, and
1793
+ - it can be decoded back from its key image.
1794
+ If both hold, we don't need to store this field in the value part of
1795
+ RocksDB's key-value pair.
1796
+ */
1797
+ if (field->part_of_key .is_set (table->s ->primary_key ))
1798
+ {
1799
+ KEY *pk_info= &table->key_info [table->s ->primary_key ];
1800
+ for (uint kp= 0 ; kp < pk_info->user_defined_key_parts ; kp++)
1801
+ {
1802
+ if (field->field_index + 1 == pk_info->key_part [kp].fieldnr )
1803
+ {
1804
+ if (pk_descr->can_unpack (kp))
1805
+ field_enc[i].skip = true ; /* Don't store */
1806
+ break ;
1807
+ }
1808
+ }
1809
+ }
1810
+
1768
1811
field_enc[i].field_type = field->real_type ();
1769
1812
1770
1813
if (field->real_maybe_null ())
0 commit comments