Skip to content

[feature](cache) Add session variable to keep INSERT source scans in the normal file cache queue - #66804

Open
raghav-reglobe wants to merge 1 commit into
apache:masterfrom
raghav-reglobe:insert-source-file-cache
Open

[feature](cache) Add session variable to keep INSERT source scans in the normal file cache queue#66804
raghav-reglobe wants to merge 1 commit into
apache:masterfrom
raghav-reglobe:insert-source-file-cache

Conversation

@raghav-reglobe

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

NereidsCoordinator.setForInsert() unconditionally sets disableFileCache(true), so the source scan of every INSERT ... SELECT / CTAS is classified into the disposable file cache queue (the comment explains the intent: keep one-shot load scans from polluting the normal LRU).

That one-shot assumption doesn't hold for a common warehouse shape: recurring ETL. Hourly dbt-style builds re-read the same source tables (in our case Iceberg external tables) every cycle — but because the disposable queue is capped at 5% of the cache and hits never promote, those scans re-fetch from remote storage every hour, forever, no matter how large the file cache is.

This PR adds an opt-in session variable, enable_file_cache_for_insert_source (default false — existing behavior is unchanged byte-for-byte). When enabled, the insert source scan uses the normal cache queue. The broker-load constructor path is deliberately untouched (no ConnectContext, genuinely one-shot).

Design notes: we considered conditioning on the target catalog instead of a variable, but the pollution question is a property of the source scan's reuse pattern, not the target — a variable lets the operator state that intent directly. Automatic frequency-based promotion between queues would be the ideal long-term answer; that's out of scope here.

Measured in production (recurring hourly ETL over Iceberg external tables, 280GB file cache per BE): after enabling, the ETL account's remote-read rate dropped ~8x within hours (23.5 GB/h -> 3 GB/h), byte-level cache hit rate rose from 64% to 78% and climbing, and fleet block hit-ratio gained ~5pp.

Release note

New session variable enable_file_cache_for_insert_source (default false): when enabled, source scans of INSERT ... SELECT / CTAS use the normal file cache queue instead of the disposable queue.

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      Behavior is opt-in and default-off (existing behavior byte-identical). Manually verified in a production deployment: with the variable enabled, insert source scans populate the normal queue (normal_queue_cache_size growth, disposable evict flatline in BE bvars) and remote reads drop as described above.
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.
      Will add the session variable to the docs site once the approach is confirmed by reviewers.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

…normal file cache queue

INSERT ... SELECT / CTAS source scans are forced onto the disposable file
cache queue to protect interactive queries from one-shot load-scan
pollution. For recurring ETL over external tables whose source working
set is ALSO the interactive working set (the same files served to
queries), that protection inverts: every cycle re-reads the same data
from remote storage and the cache can never retain it.

Add enable_file_cache_for_insert_source (default false — existing
behavior preserved). When set on the loading account/session, insert
source scans use the normal cache queue and recurring builds hit warm
data. Broker load (no session context, genuinely one-shot) keeps the
forced disposable classification.
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants