@@ -2,7 +2,7 @@ use crate::metastore::rocks_store::TableId;
2
2
use crate :: metastore:: {
3
3
get_fixed_prefix, BatchPipe , DbTableRef , IdRow , IndexId , KeyVal , MemorySequence ,
4
4
MetaStoreEvent , RocksSecondaryIndexValue , RocksSecondaryIndexValueTTLExtended ,
5
- RocksSecondaryIndexValueVersion , RocksTableStats , RowKey , SecondaryIndexInfo , SecondaryKey ,
5
+ RocksSecondaryIndexValueVersion , RocksTableStats , RowKey , SecondaryIndexInfo , SecondaryKeyHash ,
6
6
TableInfo ,
7
7
} ;
8
8
use crate :: CubeError ;
@@ -303,7 +303,7 @@ pub struct IndexScanIter<'a, RT: RocksTable + ?Sized> {
303
303
table : & ' a RT ,
304
304
index_id : u32 ,
305
305
secondary_key_val : Vec < u8 > ,
306
- secondary_key_hash : Vec < u8 > ,
306
+ secondary_key_hash : SecondaryKeyHash ,
307
307
iter : DBIterator < ' a > ,
308
308
}
309
309
@@ -364,7 +364,7 @@ where
364
364
#[ derive( Debug ) ]
365
365
pub struct SecondaryIndexValueScanIterItem {
366
366
pub row_id : u64 ,
367
- pub key_hash : SecondaryKey ,
367
+ pub key_hash : SecondaryKeyHash ,
368
368
pub ttl : Option < DateTime < Utc > > ,
369
369
pub extended : Option < RocksSecondaryIndexValueTTLExtended > ,
370
370
}
@@ -496,11 +496,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
496
496
if index. is_unique ( ) {
497
497
let hash = index. key_hash ( & row) ;
498
498
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 ( ) ) ?;
504
501
if existing_keys. len ( ) > 0 {
505
502
return Err ( CubeError :: user (
506
503
format ! (
@@ -759,7 +756,7 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
759
756
let existing_keys = self . get_row_ids_from_index (
760
757
RocksSecondaryIndex :: get_id ( secondary_index) ,
761
758
& index_val,
762
- & hash. to_be_bytes ( ) . to_vec ( ) ,
759
+ hash. to_be_bytes ( ) ,
763
760
) ?;
764
761
765
762
Ok ( existing_keys)
@@ -832,8 +829,7 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
832
829
K : Hash ,
833
830
{
834
831
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 ( ) ) ;
837
833
838
834
for id in row_ids {
839
835
if let Some ( row) = self . get_row ( id) ? {
@@ -969,7 +965,7 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
969
965
& self ,
970
966
row_id : u64 ,
971
967
secondary_index : & ' a impl RocksSecondaryIndex < Self :: T , K > ,
972
- secondary_key_hash : SecondaryKey ,
968
+ secondary_key_hash : SecondaryKeyHash ,
973
969
extended : RocksSecondaryIndexValueTTLExtended ,
974
970
batch_pipe : & mut BatchPipe ,
975
971
) -> Result < bool , CubeError >
@@ -1141,11 +1137,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
1141
1137
) -> KeyVal {
1142
1138
let hash = index. key_hash ( row) ;
1143
1139
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) ;
1149
1142
1150
1143
KeyVal {
1151
1144
key : key. to_bytes ( ) ,
@@ -1157,11 +1150,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
1157
1150
let mut res = Vec :: new ( ) ;
1158
1151
for index in Self :: indexes ( ) . iter ( ) {
1159
1152
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) ;
1165
1155
res. push ( KeyVal {
1166
1156
key : key. to_bytes ( ) ,
1167
1157
val : vec ! [ ] ,
@@ -1247,17 +1237,17 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
1247
1237
& self ,
1248
1238
secondary_id : u32 ,
1249
1239
secondary_key_val : & Vec < u8 > ,
1250
- secondary_key_hash : & Vec < u8 > ,
1240
+ secondary_key_hash : SecondaryKeyHash ,
1251
1241
) -> Result < Vec < u64 > , CubeError > {
1252
1242
let ref db = self . snapshot ( ) ;
1253
1243
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 ) ;
1256
1245
1257
1246
let mut res: Vec < u64 > = Vec :: new ( ) ;
1258
1247
1259
1248
let mut opts = ReadOptions :: default ( ) ;
1260
1249
opts. set_prefix_same_as_start ( true ) ;
1250
+
1261
1251
let iter = db. iterator_opt (
1262
1252
IteratorMode :: From ( & key_min. to_bytes ( ) [ 0 ..( key_len + 5 ) ] , Direction :: Forward ) ,
1263
1253
opts,
@@ -1269,10 +1259,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
1269
1259
if let RowKey :: SecondaryIndex ( _, secondary_index_hash, row_id) =
1270
1260
RowKey :: from_bytes ( & key)
1271
1261
{
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
1276
1264
{
1277
1265
break ;
1278
1266
}
@@ -1284,9 +1272,7 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
1284
1272
RocksSecondaryIndexValue :: HashAndTTLExtended ( h, expire, _) => ( h, expire) ,
1285
1273
} ;
1286
1274
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 ( ) {
1290
1276
continue ;
1291
1277
}
1292
1278
@@ -1341,8 +1327,9 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
1341
1327
batch : & mut WriteBatch ,
1342
1328
) -> Result < u64 , CubeError > {
1343
1329
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 ) ;
1346
1333
1347
1334
let mut opts = ReadOptions :: default ( ) ;
1348
1335
opts. set_prefix_same_as_start ( false ) ;
@@ -1408,7 +1395,8 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
1408
1395
let ref db = self . snapshot ( ) ;
1409
1396
1410
1397
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 ) ;
1412
1400
1413
1401
let mut opts = ReadOptions :: default ( ) ;
1414
1402
opts. set_prefix_same_as_start ( false ) ;
@@ -1433,16 +1421,12 @@ pub trait RocksTable: BaseRocksTable + Debug + Send + Sync {
1433
1421
{
1434
1422
let ref db = self . snapshot ( ) ;
1435
1423
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 ] ;
1440
1425
let secondary_key_val = secondary_index. key_to_bytes ( & row_key) ;
1441
1426
1442
1427
let index_id = RocksSecondaryIndex :: get_id ( secondary_index) ;
1443
1428
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 ) ;
1446
1430
1447
1431
let mut opts = ReadOptions :: default ( ) ;
1448
1432
opts. set_prefix_same_as_start ( true ) ;
0 commit comments