@ -1939,8 +1939,9 @@ void TableTest::IndexTest(BlockBasedTableOptions table_options) {
// -- Find keys do not exist, but have common prefix.
std : : vector < std : : string > prefixes = { " 001 " , " 003 " , " 005 " , " 007 " , " 009 " } ;
std : : vector < std : : string > lower_bound = { keys [ 0 ] , keys [ 1 ] , keys [ 2 ] ,
keys [ 7 ] , keys [ 9 ] , } ;
std : : vector < std : : string > lower_bound = {
keys [ 0 ] , keys [ 1 ] , keys [ 2 ] , keys [ 7 ] , keys [ 9 ] ,
} ;
// find the lower bound of the prefix
for ( size_t i = 0 ; i < prefixes . size ( ) ; + + i ) {
@ -2017,6 +2018,80 @@ void TableTest::IndexTest(BlockBasedTableOptions table_options) {
ASSERT_TRUE ( BytewiseComparator ( ) - > Compare ( prefix , ukey_prefix ) > 0 ) ;
}
}
{
// Test reseek case. It should impact partitioned index more.
ReadOptions ro ;
ro . total_order_seek = true ;
std : : unique_ptr < InternalIterator > index_iter2 ( reader - > NewIterator (
ro , moptions . prefix_extractor . get ( ) , /*arena=*/ nullptr ,
/*skip_filters=*/ false , TableReaderCaller : : kUncategorized ) ) ;
// Things to cover in partitioned index:
// 1. Both of Seek() and SeekToLast() has optimization to prevent
// rereek leaf index block if it remains to the same one, and
// they reuse the same variable.
// 2. When Next() or Prev() is called, the block moves, so the
// optimization should kick in only with the current one.
index_iter2 - > Seek ( InternalKey ( " 0055 " , 0 , kTypeValue ) . Encode ( ) ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0055 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > SeekToLast ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0095 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > Seek ( InternalKey ( " 0055 " , 0 , kTypeValue ) . Encode ( ) ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0055 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > SeekToLast ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0095 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > Prev ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
index_iter2 - > Prev ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0075 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > Seek ( InternalKey ( " 0095 " , 0 , kTypeValue ) . Encode ( ) ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0095 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > Prev ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
index_iter2 - > Prev ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0075 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > SeekToLast ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0095 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > Seek ( InternalKey ( " 0095 " , 0 , kTypeValue ) . Encode ( ) ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0095 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > Prev ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
index_iter2 - > Prev ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0075 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > Seek ( InternalKey ( " 0075 " , 0 , kTypeValue ) . Encode ( ) ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0075 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > Next ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
index_iter2 - > Next ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0095 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
index_iter2 - > SeekToLast ( ) ;
ASSERT_TRUE ( index_iter2 - > Valid ( ) ) ;
ASSERT_EQ ( " 0095 " , index_iter2 - > key ( ) . ToString ( ) . substr ( 0 , 4 ) ) ;
}
c . ResetTableReader ( ) ;
}