@@ -2,7 +2,7 @@ use crate::metastore::rocks_store::TableId;
22use crate :: metastore:: {
33 get_fixed_prefix, BatchPipe , DbTableRef , IdRow , IndexId , KeyVal , MemorySequence ,
44 MetaStoreEvent , RocksSecondaryIndexValue , RocksSecondaryIndexValueTTLExtended ,
5- RocksSecondaryIndexValueVersion , RocksTableStats , RowKey , SecondaryIndexInfo , SecondaryKey ,
5+ RocksSecondaryIndexValueVersion , RocksTableStats , RowKey , SecondaryIndexInfo , SecondaryKeyHash ,
66 TableInfo ,
77} ;
88use crate :: CubeError ;
@@ -303,7 +303,7 @@ pub struct IndexScanIter<'a, RT: RocksTable + ?Sized> {
303303 table : & ' a RT ,
304304 index_id : u32 ,
305305 secondary_key_val : Vec < u8 > ,
306- secondary_key_hash : Vec < u8 > ,
306+ secondary_key_hash : SecondaryKeyHash ,
307307 iter : DBIterator < ' a > ,
308308}
309309
@@ -364,7 +364,7 @@ where
364364#[ derive( Debug ) ]
365365pub struct SecondaryIndexValueScanIterItem {
366366 pub row_id : u64 ,
367- pub key_hash : SecondaryKey ,
367+ pub key_hash : SecondaryKeyHash ,
368368 pub ttl : Option < DateTime < Utc > > ,
369369 pub extended : Option < RocksSecondaryIndexValueTTLExtended > ,
370370}
@@ -496,11 +496,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
496496 if index. is_unique ( ) {
497497 let hash = index. key_hash ( & row) ;
498498 let index_val = index. index_key_by ( & row) ;
499- let existing_keys = self . get_row_ids_from_index (
500- index. get_id ( ) ,
501- & index_val,
502- & hash. to_be_bytes ( ) . to_vec ( ) ,
503- ) ?;
499+ let existing_keys =
500+ self . get_row_ids_from_index ( index. get_id ( ) , & index_val, hash. to_be_bytes ( ) ) ?;
504501 if existing_keys. len ( ) > 0 {
505502 return Err ( CubeError :: user (
506503 format ! (
@@ -759,7 +756,7 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
759756 let existing_keys = self . get_row_ids_from_index (
760757 RocksSecondaryIndex :: get_id ( secondary_index) ,
761758 & index_val,
762- & hash. to_be_bytes ( ) . to_vec ( ) ,
759+ hash. to_be_bytes ( ) ,
763760 ) ?;
764761
765762 Ok ( existing_keys)
@@ -832,8 +829,7 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
832829 K : Hash ,
833830 {
834831 let row_ids = self . get_row_ids_by_index ( row_key, secondary_index) ?;
835-
836- let mut res = Vec :: new ( ) ;
832+ let mut res = Vec :: with_capacity ( row_ids. len ( ) ) ;
837833
838834 for id in row_ids {
839835 if let Some ( row) = self . get_row ( id) ? {
@@ -969,7 +965,7 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
969965 & self ,
970966 row_id : u64 ,
971967 secondary_index : & ' a impl RocksSecondaryIndex < Self :: T , K > ,
972- secondary_key_hash : SecondaryKey ,
968+ secondary_key_hash : SecondaryKeyHash ,
973969 extended : RocksSecondaryIndexValueTTLExtended ,
974970 batch_pipe : & mut BatchPipe ,
975971 ) -> Result < bool , CubeError >
@@ -1141,11 +1137,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
11411137 ) -> KeyVal {
11421138 let hash = index. key_hash ( row) ;
11431139 let index_val = index. index_value ( row) ;
1144- let key = RowKey :: SecondaryIndex (
1145- Self :: index_id ( index. get_id ( ) ) ,
1146- hash. to_be_bytes ( ) . to_vec ( ) ,
1147- row_id,
1148- ) ;
1140+ let key =
1141+ RowKey :: SecondaryIndex ( Self :: index_id ( index. get_id ( ) ) , hash. to_be_bytes ( ) , row_id) ;
11491142
11501143 KeyVal {
11511144 key : key. to_bytes ( ) ,
@@ -1157,11 +1150,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
11571150 let mut res = Vec :: new ( ) ;
11581151 for index in Self :: indexes ( ) . iter ( ) {
11591152 let hash = index. key_hash ( & row) ;
1160- let key = RowKey :: SecondaryIndex (
1161- Self :: index_id ( index. get_id ( ) ) ,
1162- hash. to_be_bytes ( ) . to_vec ( ) ,
1163- row_id,
1164- ) ;
1153+ let key =
1154+ RowKey :: SecondaryIndex ( Self :: index_id ( index. get_id ( ) ) , hash. to_be_bytes ( ) , row_id) ;
11651155 res. push ( KeyVal {
11661156 key : key. to_bytes ( ) ,
11671157 val : vec ! [ ] ,
@@ -1247,17 +1237,17 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
12471237 & self ,
12481238 secondary_id : u32 ,
12491239 secondary_key_val : & Vec < u8 > ,
1250- secondary_key_hash : & Vec < u8 > ,
1240+ secondary_key_hash : SecondaryKeyHash ,
12511241 ) -> Result < Vec < u64 > , CubeError > {
12521242 let ref db = self . snapshot ( ) ;
12531243 let key_len = secondary_key_hash. len ( ) ;
1254- let key_min =
1255- RowKey :: SecondaryIndex ( Self :: index_id ( secondary_id) , secondary_key_hash. clone ( ) , 0 ) ;
1244+ let key_min = RowKey :: SecondaryIndex ( Self :: index_id ( secondary_id) , secondary_key_hash, 0 ) ;
12561245
12571246 let mut res: Vec < u64 > = Vec :: new ( ) ;
12581247
12591248 let mut opts = ReadOptions :: default ( ) ;
12601249 opts. set_prefix_same_as_start ( true ) ;
1250+
12611251 let iter = db. iterator_opt (
12621252 IteratorMode :: From ( & key_min. to_bytes ( ) [ 0 ..( key_len + 5 ) ] , Direction :: Forward ) ,
12631253 opts,
@@ -1269,10 +1259,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
12691259 if let RowKey :: SecondaryIndex ( _, secondary_index_hash, row_id) =
12701260 RowKey :: from_bytes ( & key)
12711261 {
1272- if !secondary_index_hash
1273- . iter ( )
1274- . zip ( secondary_key_hash)
1275- . all ( |( a, b) | a == b)
1262+ if secondary_index_hash. len ( ) != secondary_key_hash. len ( )
1263+ || secondary_index_hash != secondary_key_hash
12761264 {
12771265 break ;
12781266 }
@@ -1284,9 +1272,7 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
12841272 RocksSecondaryIndexValue :: HashAndTTLExtended ( h, expire, _) => ( h, expire) ,
12851273 } ;
12861274
1287- if secondary_key_val. len ( ) != hash. len ( )
1288- || !hash. iter ( ) . zip ( secondary_key_val) . all ( |( a, b) | a == b)
1289- {
1275+ if hash. len ( ) != secondary_key_val. len ( ) || hash != secondary_key_val. as_slice ( ) {
12901276 continue ;
12911277 }
12921278
@@ -1341,8 +1327,9 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
13411327 batch : & mut WriteBatch ,
13421328 ) -> Result < u64 , CubeError > {
13431329 let ref db = self . snapshot ( ) ;
1344- let zero_vec = vec ! [ 0 as u8 ; 8 ] ;
1345- let key_min = RowKey :: SecondaryIndex ( Self :: index_id ( secondary_id) , zero_vec. clone ( ) , 0 ) ;
1330+
1331+ let zero_vec = [ 0 as u8 ; 8 ] ;
1332+ let key_min = RowKey :: SecondaryIndex ( Self :: index_id ( secondary_id) , zero_vec, 0 ) ;
13461333
13471334 let mut opts = ReadOptions :: default ( ) ;
13481335 opts. set_prefix_same_as_start ( false ) ;
@@ -1408,7 +1395,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
14081395 let ref db = self . snapshot ( ) ;
14091396
14101397 let index_id = RocksSecondaryIndex :: get_id ( secondary_index) ;
1411- let row_key = RowKey :: SecondaryIndex ( Self :: index_id ( index_id) , vec ! [ ] , 0 ) ;
1398+ let zero_vec = [ 0 as u8 ; 8 ] ;
1399+ let row_key = RowKey :: SecondaryIndex ( Self :: index_id ( index_id) , zero_vec, 0 ) ;
14121400
14131401 let mut opts = ReadOptions :: default ( ) ;
14141402 opts. set_prefix_same_as_start ( false ) ;
@@ -1433,16 +1421,12 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
14331421 {
14341422 let ref db = self . snapshot ( ) ;
14351423
1436- let secondary_key_hash = secondary_index
1437- . typed_key_hash ( & row_key)
1438- . to_be_bytes ( )
1439- . to_vec ( ) ;
1424+ let secondary_key_hash = secondary_index. typed_key_hash ( & row_key) . to_be_bytes ( ) as [ u8 ; 8 ] ;
14401425 let secondary_key_val = secondary_index. key_to_bytes ( & row_key) ;
14411426
14421427 let index_id = RocksSecondaryIndex :: get_id ( secondary_index) ;
14431428 let key_len = secondary_key_hash. len ( ) ;
1444- let key_min =
1445- RowKey :: SecondaryIndex ( Self :: index_id ( index_id) , secondary_key_hash. clone ( ) , 0 ) ;
1429+ let key_min = RowKey :: SecondaryIndex ( Self :: index_id ( index_id) , secondary_key_hash, 0 ) ;
14461430
14471431 let mut opts = ReadOptions :: default ( ) ;
14481432 opts. set_prefix_same_as_start ( true ) ;
0 commit comments