@@ -117,15 +117,16 @@ pub async fn table_to_query(
117117 BoundsCalcType :: Skip => { }
118118 BoundsCalcType :: Calc => {
119119 debug ! ( "Computing {} table bounds for {id}" , info. format_id( ) ) ;
120- info. bounds = calc_bounds ( & pool, & schema, & table, & geometry_column, srid) . await ?;
120+ info. bounds =
121+ calc_bounds ( & pool, & schema, & table, & geometry_column, srid, false ) . await ?;
121122 }
122123 BoundsCalcType :: Quick => {
123124 debug ! (
124125 "Computing {} table bounds with {}s timeout for {id}" ,
125126 info. format_id( ) ,
126127 DEFAULT_BOUNDS_TIMEOUT . as_secs( )
127128 ) ;
128- let bounds = calc_bounds ( & pool, & schema, & table, & geometry_column, srid) ;
129+ let bounds = calc_bounds ( & pool, & schema, & table, & geometry_column, srid, true ) ;
129130 pin_mut ! ( bounds) ;
130131 if let Ok ( bounds) = timeout ( DEFAULT_BOUNDS_TIMEOUT , & mut bounds) . await {
131132 info. bounds = bounds?;
@@ -217,10 +218,12 @@ async fn calc_bounds(
217218 table : & str ,
218219 geometry_column : & str ,
219220 srid : i32 ,
221+ is_quick : bool ,
220222) -> PgResult < Option < Bounds > > {
221- Ok ( pool. get ( )
222- . await ?
223- . query_one ( & format ! (
223+ let sql = if is_quick {
224+ format ! ( "SELECT ST_EstimatedExtent('{schema}', '{table}', '{geometry_column}') as bounds" )
225+ } else {
226+ format ! (
224227 r#"
225228WITH real_bounds AS (SELECT ST_SetSRID(ST_Extent({geometry_column}), {srid}) AS rb FROM {schema}.{table})
226229SELECT ST_Transform(
@@ -232,7 +235,14 @@ SELECT ST_Transform(
232235 4326
233236 ) AS bounds
234237FROM {schema}.{table};
235- "# ) , & [ ] )
238+ "#
239+ )
240+ } ;
241+
242+ Ok ( pool
243+ . get ( )
244+ . await ?
245+ . query_one ( & sql, & [ ] )
236246 . await
237247 . map_err ( |e| PostgresError ( e, "querying table bounds" ) ) ?
238248 . get :: < _ , Option < ewkb:: Polygon > > ( "bounds" )
0 commit comments