@@ -23,6 +23,7 @@ use std::sync::Arc;
2323
2424use chrono:: Duration ;
2525use chrono:: TimeDelta ;
26+ use databend_common_base:: base:: tokio;
2627use databend_common_catalog:: catalog:: StorageDescription ;
2728use databend_common_catalog:: plan:: DataSourcePlan ;
2829use databend_common_catalog:: plan:: PartStatistics ;
@@ -130,8 +131,11 @@ pub struct FuseTable {
130131
131132 table_type : FuseTableType ,
132133
133- // If this is set, reading from fuse_table should only returns the increment blocks
134+ // If this is set, reading from fuse_table should only return the increment blocks
134135 pub ( crate ) changes_desc : Option < ChangesDesc > ,
136+
137+ // A table instance level cache of snapshot_location, if this table is attaching to someone else.
138+ attached_table_location : tokio:: sync:: OnceCell < String > ,
135139}
136140
137141impl FuseTable {
@@ -238,6 +242,7 @@ impl FuseTable {
238242 table_compression : table_compression. as_str ( ) . try_into ( ) ?,
239243 table_type,
240244 changes_desc : None ,
245+ attached_table_location : Default :: default ( ) ,
241246 } ) )
242247 }
243248
@@ -368,15 +373,25 @@ impl FuseTable {
368373 let options = self . table_info . options ( ) ;
369374
370375 if let Some ( storage_prefix) = options. get ( OPT_KEY_STORAGE_PREFIX ) {
371- // if table is attached, parse snapshot location from hint file
372- let hint = format ! ( "{}/{}" , storage_prefix, FUSE_TBL_LAST_SNAPSHOT_HINT ) ;
373- let snapshot_loc = {
374- let hint_content = self . operator . read ( & hint) . await ?. to_vec ( ) ;
375- let snapshot_full_path = String :: from_utf8 ( hint_content) ?;
376- let operator_info = self . operator . info ( ) ;
377- snapshot_full_path[ operator_info. root ( ) . len ( ) ..] . to_string ( )
378- } ;
379- Ok ( Some ( snapshot_loc) )
376+ // If the table is attaching to someone else,
377+ // parse the snapshot location from the hint file.
378+ //
379+ // The snapshot location is allowed
380+ // to be fetched from the table level instance cache.
381+ let snapshot_location = self
382+ . attached_table_location
383+ . get_or_try_init ( || async {
384+ let hint =
385+ format ! ( "{}/{}" , storage_prefix, FUSE_TBL_LAST_SNAPSHOT_HINT ) ;
386+ let hint_content = self . operator . read ( & hint) . await ?. to_vec ( ) ;
387+ let snapshot_full_path = String :: from_utf8 ( hint_content) ?;
388+ let operator_info = self . operator . info ( ) ;
389+ Ok :: < _ , ErrorCode > (
390+ snapshot_full_path[ operator_info. root ( ) . len ( ) ..] . to_string ( ) ,
391+ )
392+ } )
393+ . await ?;
394+ Ok ( Some ( snapshot_location. to_owned ( ) ) )
380395 } else {
381396 Ok ( options
382397 . get ( OPT_KEY_SNAPSHOT_LOCATION )
0 commit comments