@@ -186,6 +186,12 @@ pub struct Catalog {
186
186
/// Whether the database supports `int4_minmax_multi_ops` etc.
187
187
/// See the [Postgres docs](https://www.postgresql.org/docs/15/brin-builtin-opclasses.html)
188
188
has_minmax_multi_ops : bool ,
189
+
190
+ /// Whether the column `pg_stats.range_bounds_histogram` introduced in
191
+ /// Postgres 17 exists. See the [Postgres
192
+ /// docs](https://www.postgresql.org/docs/17/view-pg-stats.html)
193
+ #[ allow( dead_code) ]
194
+ pg_stats_has_range_bounds_histogram : bool ,
189
195
}
190
196
191
197
impl Catalog {
@@ -199,6 +205,7 @@ impl Catalog {
199
205
let text_columns = get_text_columns ( conn, & site. namespace ) ?;
200
206
let use_poi = supports_proof_of_indexing ( conn, & site. namespace ) ?;
201
207
let has_minmax_multi_ops = has_minmax_multi_ops ( conn) ?;
208
+ let pg_stats_has_range_bounds_histogram = pg_stats_has_range_bounds_histogram ( conn) ?;
202
209
203
210
Ok ( Catalog {
204
211
site,
@@ -207,6 +214,7 @@ impl Catalog {
207
214
use_bytea_prefix,
208
215
entities_with_causality_region : entities_with_causality_region. into_iter ( ) . collect ( ) ,
209
216
has_minmax_multi_ops,
217
+ pg_stats_has_range_bounds_histogram,
210
218
} )
211
219
}
212
220
@@ -217,6 +225,7 @@ impl Catalog {
217
225
entities_with_causality_region : BTreeSet < EntityType > ,
218
226
) -> Result < Self , StoreError > {
219
227
let has_minmax_multi_ops = has_minmax_multi_ops ( conn) ?;
228
+ let pg_stats_has_range_bounds_histogram = pg_stats_has_range_bounds_histogram ( conn) ?;
220
229
221
230
Ok ( Catalog {
222
231
site,
@@ -228,6 +237,7 @@ impl Catalog {
228
237
use_bytea_prefix : true ,
229
238
entities_with_causality_region,
230
239
has_minmax_multi_ops,
240
+ pg_stats_has_range_bounds_histogram,
231
241
} )
232
242
}
233
243
@@ -245,6 +255,7 @@ impl Catalog {
245
255
use_bytea_prefix : true ,
246
256
entities_with_causality_region,
247
257
has_minmax_multi_ops : false ,
258
+ pg_stats_has_range_bounds_histogram : false ,
248
259
} )
249
260
}
250
261
@@ -975,6 +986,28 @@ fn has_minmax_multi_ops(conn: &mut PgConnection) -> Result<bool, StoreError> {
975
986
Ok ( sql_query ( QUERY ) . get_result :: < Ops > ( conn) ?. has_ops )
976
987
}
977
988
989
+ /// Check whether the database for `conn` has the column
990
+ /// `pg_stats.range_bounds_histogram` introduced in Postgres 17
991
+ fn pg_stats_has_range_bounds_histogram ( conn : & mut PgConnection ) -> Result < bool , StoreError > {
992
+ #[ derive( Queryable , QueryableByName ) ]
993
+ struct HasIt {
994
+ #[ diesel( sql_type = Bool ) ]
995
+ has_it : bool ,
996
+ }
997
+
998
+ let query = "
999
+ select exists (\
1000
+ select 1 \
1001
+ from information_schema.columns \
1002
+ where table_name = 'pg_stats' \
1003
+ and table_schema = 'pg_catalog' \
1004
+ and column_name = 'range_bounds_histogram') as has_it";
1005
+ sql_query ( query)
1006
+ . get_result :: < HasIt > ( conn)
1007
+ . map ( |h| h. has_it )
1008
+ . map_err ( StoreError :: from)
1009
+ }
1010
+
978
1011
pub ( crate ) fn histogram_bounds (
979
1012
conn : & mut PgConnection ,
980
1013
namespace : & Namespace ,
0 commit comments