@@ -2696,7 +2696,8 @@ int ha_rocksdb::index_read_map(uchar *buf, const uchar *key,
2696
2696
keypart_map);
2697
2697
2698
2698
if (find_flag == HA_READ_PREFIX_LAST_OR_PREV ||
2699
- find_flag == HA_READ_PREFIX_LAST)
2699
+ find_flag == HA_READ_PREFIX_LAST ||
2700
+ find_flag == HA_READ_AFTER_KEY)
2700
2701
{
2701
2702
/* See below */
2702
2703
kd->successor (sec_key_packed_tuple, packed_size);
@@ -2715,7 +2716,7 @@ int ha_rocksdb::index_read_map(uchar *buf, const uchar *key,
2715
2716
greater than the lookup tuple.
2716
2717
*/
2717
2718
setup_index_scan (kd, &slice, use_all_keys, is_ascending (kd, find_flag));
2718
- bool move_forward= true ;
2719
+ // bool move_forward= true;
2719
2720
2720
2721
2721
2722
switch (find_flag) {
@@ -2753,11 +2754,45 @@ int ha_rocksdb::index_read_map(uchar *buf, const uchar *key,
2753
2754
}
2754
2755
break ;
2755
2756
}
2757
+ case HA_READ_BEFORE_KEY:
2758
+ {
2759
+ // move_forward= false;
2760
+ /* We want to read the record that's right *before* the given key. */
2761
+ if (!scan_it->Valid ())
2762
+ {
2763
+ /*
2764
+ All the values in the database are smaller than our key. Two cases
2765
+ - our index is the last in db. Its last value is a match
2766
+ - our index has no records (in that case we will get a record from
2767
+ our index and detect it below)
2768
+ */
2769
+ scan_it->SeekToLast ();
2770
+ }
2771
+ else
2772
+ {
2773
+ /*
2774
+ RocksDB iterator is positioned at "the first key in the source that
2775
+ at or past target".
2776
+ We need to step one key back, so that we're at the last key that is
2777
+ before the target.
2778
+ If the passed key is greater than the max. value that is found in the
2779
+ table, then iterator is pointing at the *first* record in subsequent
2780
+ table/index.
2781
+ */
2782
+ scan_it->Prev ();
2783
+ }
2784
+ /* fall through */
2785
+ }
2786
+ case HA_READ_AFTER_KEY:
2756
2787
case HA_READ_KEY_OR_NEXT:
2757
2788
{
2758
2789
/*
2759
2790
We are looking for the first record such that
2760
- index_tuple >= lookup_tuple.
2791
+
2792
+ index_tuple $GT lookup_tuple
2793
+
2794
+ with HA_READ_AFTER_KEY, $GT = '>',
2795
+ with HA_READ_KEY_OR_NEXT, $GT = '>='
2761
2796
*/
2762
2797
if (key_descr[active_index]->is_reverse_cf )
2763
2798
{
@@ -2768,8 +2803,9 @@ int ha_rocksdb::index_read_map(uchar *buf, const uchar *key,
2768
2803
else
2769
2804
{
2770
2805
/*
2771
- When using a full extended key tuple: we should not step back if
2772
- we've found an exact match.
2806
+ We should step back
2807
+ - when not using full extended key
2808
+ - when using full extended key and when we've got an exact match
2773
2809
*/
2774
2810
rkey= scan_it->key ();
2775
2811
if (!using_full_key || !kd->value_matches_prefix (rkey, slice))
@@ -2794,61 +2830,6 @@ int ha_rocksdb::index_read_map(uchar *buf, const uchar *key,
2794
2830
}
2795
2831
break ;
2796
2832
}
2797
- case HA_READ_BEFORE_KEY:
2798
- {
2799
- move_forward= false ;
2800
- /* We want to read the record that's right *before* the given key. */
2801
- if (!scan_it->Valid ())
2802
- {
2803
- /*
2804
- All the values in the database are smaller than our key. Two cases
2805
- - our index is the last in db. Its last value is a match
2806
- - our index has no records (in that case we will get a record from
2807
- our index and detect it below)
2808
- */
2809
- scan_it->SeekToLast ();
2810
- }
2811
- else
2812
- {
2813
- /*
2814
- RocksDB iterator is positioned at "the first key in the source that
2815
- at or past target".
2816
- We need to step one key back, so that we're at the last key that is
2817
- before the target.
2818
- If the passed key is greater than the max. value that is found in the
2819
- table, then iterator is pointing at the *first* record in subsequent
2820
- table/index.
2821
- */
2822
- scan_it->Prev ();
2823
- }
2824
- /* fall through */
2825
- }
2826
- case HA_READ_AFTER_KEY:
2827
- {
2828
- bool in_key;
2829
- bool have_row;
2830
- /*
2831
- Walk forward until we've found a record that is not equal to the lookup
2832
- tuple, but still belongs to this index.
2833
- */
2834
- while ((have_row= scan_it->Valid ()))
2835
- {
2836
- rkey= scan_it->key ();
2837
- if (!(in_key= kd->covers_key (rkey.data (), rkey.size ())) ||
2838
- kd->cmp_full_keys (rkey.data (), rkey.size (),
2839
- slice.data (), slice.size (),
2840
- n_used_parts))
2841
- break ;
2842
-
2843
- if (move_forward)
2844
- scan_it->Next ();
2845
- else
2846
- scan_it->Prev ();
2847
- }
2848
- if (!have_row || !in_key)
2849
- rc= HA_ERR_END_OF_FILE;
2850
- break ;
2851
- }
2852
2833
case HA_READ_KEY_OR_PREV:
2853
2834
{
2854
2835
if (!scan_it->Valid ())
0 commit comments