Commit e6049de
authored
Make default ListingFilesCache table scoped (#19616)
## Which issue does this PR close?
<!--
We generally require a GitHub issue to be filed for all bug fixes and
enhancements and this helps us generate change logs for our releases.
You can link an issue to this PR using the GitHub syntax. For example
`Closes #123` indicates that this PR will close issue #123.
-->
- Builds on #19388
- Closes #19573
## Rationale for this change
<!--
Why are you proposing this change? If this is already explained clearly
in the issue then this section is not needed.
Explaining clearly why changes are proposed helps reviewers understand
your changes and offer better suggestions for fixes.
-->
This PR explores one way to make `ListFilesCache` table scoped. A
session level cache is still used, but the cache key is made a
"table-scoped" path, for which a new struct
```
pub struct TableScopedPath(pub Option<TableReference>, pub Path);
```
is defined. `TableReference` comes from `CreateExternalTable` passed to
`ListingTableFactory::create`.
Additionally, when a table is dropped, all entries related to a table is
dropped by modifying `SessionContext::find_and_deregister` method.
Testing (change on adding `list_files_cache()` for cli is included for
easier testing).
- Testing cache reuse on a single table.
```
> \object_store_profiling summary
ObjectStore Profile mode set to Summary
> create external table test
stored as parquet
location 's3://overturemaps-us-west-2/release/2025-12-17.0/theme=base/';
0 row(s) fetched.
Elapsed 14.878 seconds.
Object Store Profiling
Instrumented Object Store: instrument_mode: Summary, inner: AmazonS3(overturemaps-us-west-2)
Summaries:
+-----------+----------+-----------+-----------+-------------+-------------+-------+
| Operation | Metric | min | max | avg | sum | count |
+-----------+----------+-----------+-----------+-------------+-------------+-------+
| Get | duration | 0.030597s | 0.209235s | 0.082396s | 36.254189s | 440 |
| Get | size | 204782 B | 857230 B | 497304.88 B | 218814144 B | 440 |
| List | duration | 0.192037s | 0.192037s | 0.192037s | 0.192037s | 1 |
| List | size | | | | | 1 |
+-----------+----------+-----------+-----------+-------------+-------------+-------+
> select table, path, unnest(metadata_list) from list_files_cache() limit 1;
+-------+---------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| table | path | UNNEST(list_files_cache().metadata_list) |
+-------+---------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| test | release/2025-12-17.0/theme=base | {file_path: release/2025-12-17.0/theme=base/type=bathymetry/part-00000-dd0f2f50-b436-4710-996f-f1b06181a3a1-c000.zstd.parquet, file_modified: 2025-12-17T22:32:50, file_size_bytes: 40280159, e_tag: "15090401f8f936c3f83bb498cb99a41d-3", version: NULL} |
+-------+---------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row(s) fetched.
Elapsed 0.058 seconds.
Object Store Profiling
> select count(*) from test where type = 'infrastructure';
+-----------+
| count(*) |
+-----------+
| 142969564 |
+-----------+
1 row(s) fetched.
Elapsed 0.028 seconds.
Object Store Profiling
```
- Test separate cache entries are created for two tables with same path
```
> create external table test2
stored as parquet
location 's3://overturemaps-us-west-2/release/2025-12-17.0/theme=base/';
0 row(s) fetched.
Elapsed 14.798 seconds.
Object Store Profiling
Instrumented Object Store: instrument_mode: Summary, inner: AmazonS3(overturemaps-us-west-2)
Summaries:
+-----------+----------+-----------+-----------+-------------+-------------+-------+
| Operation | Metric | min | max | avg | sum | count |
+-----------+----------+-----------+-----------+-------------+-------------+-------+
| Get | duration | 0.030238s | 0.350465s | 0.073670s | 32.414654s | 440 |
| Get | size | 204782 B | 857230 B | 497304.88 B | 218814144 B | 440 |
| List | duration | 0.133334s | 0.133334s | 0.133334s | 0.133334s | 1 |
| List | size | | | | | 1 |
+-----------+----------+-----------+-----------+-------------+-------------+-------+
> select count(*) from test2 where type = 'bathymetry';
+----------+
| count(*) |
+----------+
| 59963 |
+----------+
1 row(s) fetched.
Elapsed 0.009 seconds.
Object Store Profiling
> select table, path from list_files_cache();
+-------+---------------------------------+
| table | path |
+-------+---------------------------------+
| test | release/2025-12-17.0/theme=base |
| test2 | release/2025-12-17.0/theme=base |
+-------+---------------------------------+
2 row(s) fetched.
Elapsed 0.004 seconds.
```
- Test cache associated with a table is dropped when table is dropped,
and the other table with same path is unaffected.
```
> drop table test;
0 row(s) fetched.
Elapsed 0.015 seconds.
Object Store Profiling
> select table, path from list_files_cache();
+-------+---------------------------------+
| table | path |
+-------+---------------------------------+
| test2 | release/2025-12-17.0/theme=base |
+-------+---------------------------------+
1 row(s) fetched.
Elapsed 0.005 seconds.
Object Store Profiling
> select count(*) from list_files_cache() where table = 'test';
+----------+
| count(*) |
+----------+
| 0 |
+----------+
1 row(s) fetched.
Elapsed 0.014 seconds.
> select count(*) from test2 where type = 'infrastructure';
+-----------+
| count(*) |
+-----------+
| 142969564 |
+-----------+
1 row(s) fetched.
Elapsed 0.013 seconds.
Object Store Profiling
```
- Test that dropping a view does not remove cache
```
> create view test2_view as (select * from test2 where type = 'infrastructure');
0 row(s) fetched.
Elapsed 0.103 seconds.
Object Store Profiling
> select count(*) from test2_view;
+-----------+
| count(*) |
+-----------+
| 142969564 |
+-----------+
1 row(s) fetched.
Elapsed 0.094 seconds.
Object Store Profiling
> drop view test2_view;
0 row(s) fetched.
Elapsed 0.002 seconds.
Object Store Profiling
> select table, path from list_files_cache();
+-------+---------------------------------+
| table | path |
+-------+---------------------------------+
| test2 | release/2025-12-17.0/theme=base |
+-------+---------------------------------+
1 row(s) fetched.
Elapsed 0.007 seconds.
```
## What changes are included in this PR?
<!--
There is no need to duplicate the description in the issue here but it
is sometimes worth providing a summary of the individual changes in this
PR.
-->
## Are these changes tested?
<!--
We typically require tests for all PRs in order to:
1. Prevent the code from being accidentally broken by subsequent changes
2. Serve as another way to document the expected behavior of the code
If tests are not included in your PR, please explain why (for example,
are they covered by existing tests)?
-->
## Are there any user-facing changes?
<!--
If there are user-facing changes then we may require documentation to be
updated before approving the PR.
-->
<!--
If there are any breaking changes to public APIs, please add the `api
change` label.
-->1 parent 1d5d63c commit e6049de
File tree
10 files changed
+474
-184
lines changed- datafusion-cli/src
- datafusion
- catalog-listing/src
- core/src
- datasource
- execution/context
- datasource/src
- execution/src/cache
- docs/source/user-guide/cli
10 files changed
+474
-184
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
703 | 703 | | |
704 | 704 | | |
705 | 705 | | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
| 712 | + | |
| 713 | + | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
706 | 723 | | |
707 | 724 | | |
708 | 725 | | |
| |||
771 | 788 | | |
772 | 789 | | |
773 | 790 | | |
| 791 | + | |
774 | 792 | | |
775 | 793 | | |
776 | 794 | | |
| |||
786 | 804 | | |
787 | 805 | | |
788 | 806 | | |
| 807 | + | |
789 | 808 | | |
790 | 809 | | |
791 | 810 | | |
| |||
802 | 821 | | |
803 | 822 | | |
804 | 823 | | |
805 | | - | |
| 824 | + | |
| 825 | + | |
806 | 826 | | |
807 | 827 | | |
808 | 828 | | |
| |||
841 | 861 | | |
842 | 862 | | |
843 | 863 | | |
| 864 | + | |
844 | 865 | | |
845 | 866 | | |
846 | 867 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
848 | 848 | | |
849 | 849 | | |
850 | 850 | | |
851 | | - | |
852 | | - | |
853 | | - | |
854 | | - | |
855 | | - | |
856 | | - | |
857 | | - | |
858 | | - | |
859 | | - | |
860 | | - | |
861 | | - | |
862 | | - | |
863 | | - | |
864 | | - | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
873 | | - | |
874 | | - | |
875 | | - | |
876 | | - | |
877 | | - | |
878 | | - | |
879 | | - | |
880 | | - | |
881 | | - | |
882 | 851 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
565 | 566 | | |
566 | 567 | | |
567 | 568 | | |
568 | | - | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
569 | 574 | | |
570 | 575 | | |
571 | 576 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
66 | | - | |
| 66 | + | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
160 | 161 | | |
161 | 162 | | |
162 | 163 | | |
163 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
164 | 167 | | |
165 | 168 | | |
166 | 169 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1322 | 1322 | | |
1323 | 1323 | | |
1324 | 1324 | | |
1325 | | - | |
| 1325 | + | |
1326 | 1326 | | |
1327 | 1327 | | |
1328 | 1328 | | |
| |||
1334 | 1334 | | |
1335 | 1335 | | |
1336 | 1336 | | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
1337 | 1342 | | |
1338 | 1343 | | |
1339 | 1344 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
| 45 | + | |
| 46 | + | |
44 | 47 | | |
45 | 48 | | |
46 | 49 | | |
| |||
145 | 148 | | |
146 | 149 | | |
147 | 150 | | |
148 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
149 | 157 | | |
150 | 158 | | |
151 | 159 | | |
| |||
255 | 263 | | |
256 | 264 | | |
257 | 265 | | |
258 | | - | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
259 | 274 | | |
260 | 275 | | |
261 | 276 | | |
| |||
264 | 279 | | |
265 | 280 | | |
266 | 281 | | |
267 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
268 | 290 | | |
269 | 291 | | |
270 | 292 | | |
| |||
323 | 345 | | |
324 | 346 | | |
325 | 347 | | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
326 | 357 | | |
327 | 358 | | |
328 | 359 | | |
| |||
345 | 376 | | |
346 | 377 | | |
347 | 378 | | |
| 379 | + | |
348 | 380 | | |
349 | 381 | | |
350 | 382 | | |
| |||
367 | 399 | | |
368 | 400 | | |
369 | 401 | | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
370 | 407 | | |
371 | 408 | | |
372 | | - | |
| 409 | + | |
373 | 410 | | |
374 | 411 | | |
375 | 412 | | |
| |||
380 | 417 | | |
381 | 418 | | |
382 | 419 | | |
383 | | - | |
| 420 | + | |
384 | 421 | | |
385 | 422 | | |
386 | 423 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
| |||
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | | - | |
| 86 | + | |
85 | 87 | | |
86 | 88 | | |
87 | 89 | | |
| |||
96 | 98 | | |
97 | 99 | | |
98 | 100 | | |
99 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
100 | 104 | | |
101 | 105 | | |
102 | 106 | | |
| |||
0 commit comments