[Bug] INSERT ... SELECT with a source planned empty leaves its InsertLoadJob PENDING forever (FE memory leak, follow-up to #62282)
Search before asking
- [x] I had searched in the issues and found no similar issues.
Version
4.1.3 (cloud mode). The same code path is present in 4.1.5-release and master.
What's Wrong?
An OLAP INSERT INTO ... SELECT whose source the planner reduces to an empty set (for example, partition pruning on a
LIST-partitioned table with no partition for the filtered value) leaves an InsertLoadJob in PENDING state in the master
FE's LoadManager permanently. These jobs are never cleaned up and accumulate until the FE restarts.
This is a path that #62282 (backport #62889) did not cover:
- For a normal OLAP insert,
InsertIntoTableCommandbuildsOlapInsertExecutorwithneedRegister = (jobId != -1)(InsertIntoTableCommand.java#L447-L448), and the constructor immediately callsLoadManager.addLoadJobwith a newInsertLoadJobinPENDING(AbstractInsertExecutor.java#L110-L112). - If the sink's child is a
PhysicalEmptyRelation,runInternalreturns early, becauseshouldExecuteEmptyInsert()isfalsefor OLAP tables (InsertIntoTableCommand.java#L634-L638).onComplete/afterExecnever run, soOlapInsertExecutor.recordLoadJob→LoadManager.recordFinishedLoadJob, the only transition toFINISHED/CANCELLED, is never called. - The job can never be removed:
LoadJob.isExpired()returnsfalsefor uncompleted jobs (LoadJob.java#L1137-L1140), andremoveOverLimitLoadJobonly removes completed jobs. It is also never written to the edit log, so it disappears on an FE restart and nowhere else.
On master the early return is if (!insertExecutor.requiresTransaction()) return;, with the same effect for OLAP tables.
Impact observed on a production cluster (16 GiB master FE heap; a workload issuing many per-tenant INSERT ... SELECT
statements that filter a LIST-partitioned table on a tenant that often has no partition):
doris_fe_job{job="load", type="INSERT", state="PENDING"}on the master grows by ~140k/day and only drops when the FE restarts (1.24M → 261 at one restart, then 1.97M after 13 days).- Master heap still in use after GC grows ~3.2 KB per stuck job (~0.44 GiB/day). It reset together with the count at the restart, while the followers' heap stayed flat.
- Once the heap fills, the master runs a stop-the-world full GC every ~5 minutes, ~2.3 s each, stalling commits and DDL for the whole cluster.
- Once more than
label_num_threshold(2000) jobs are stuck, the hourlyLoadLabelCleanerdeletes every finished load job on each run (removeOverLimitLoadJobcan never get below the threshold).SHOW LOADtherefore keeps less than an hour of history instead ofstreaming_label_keep_max_second/label_keep_max_second. - Every metrics scrape (
MetricRepo.getMetric→LoadManager.getLoadJobNum) and every cleaner run walks all the stuck jobs.
From the audit log, the stuck jobs match, hour by hour (98%), the INSERTs that return OK with 0 rows, 0 scanned rows and a
query time of a few ms, and EXPLAIN of their SELECT shows a single 0:VEMPTYSET node.
What You Expected?
An INSERT whose source is planned empty finishes its load job (as FINISHED with 0 rows, like an executed INSERT that
writes nothing) or never registers one, so nothing is left in LoadManager.
How to Reproduce?
CREATE TABLE src (k VARCHAR(16) NOT NULL, v INT)
DUPLICATE KEY(k)
AUTO PARTITION BY LIST (k) ()
DISTRIBUTED BY HASH(k) BUCKETS 1
PROPERTIES ("replication_num" = "1");
CREATE TABLE dst (k VARCHAR(16) NOT NULL, v INT)
DUPLICATE KEY(k)
AUTO PARTITION BY LIST (k) ()
DISTRIBUTED BY HASH(k) BUCKETS 1
PROPERTIES ("replication_num" = "1");
INSERT INTO src VALUES ('a', 1);
-- 'b' has no partition in src: the plan is a single VEMPTYSET
EXPLAIN SELECT * FROM src WHERE k = 'b';
-- returns OK, 0 rows; repeat it a few times
INSERT INTO dst SELECT * FROM src WHERE k = 'b';
Then on the master FE:
curl -s http://<master-fe>:8030/metrics | grep 'doris_fe_job{job="load", type="INSERT", state="PENDING"}'
The value goes up by one per INSERT and never goes down. It stays the same after label_clean_interval_second, and drops
only when the FE restarts.
Anything Else?
Possible fixes, in order of preference:
- In the empty-source branch of
runInternal, record the job as finished (0 rows) before returning, asafterExecdoes for an executed insert, soSHOW LOADstays consistent. - Alternatively, register the job only after the empty check, when the insert actually executes.
As defense in depth, it may also be worth letting the label cleaner expire PENDING insert jobs older than the insert
timeout. That would stop any future path like this from growing the heap without bound.
Workaround on the client side: skip INSERTs whose EXPLAIN is a single VEMPTYSET node. They would write nothing anyway.
Are you willing to submit PR?
- [x] Yes I am willing to submit a PR!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Breakwater-GitHub-Analysis-Slot: slot_a4f61110efc2
Assessment: The reported path is supported by source inspection: a normal OLAP insert can register an InsertLoadJob and then return successfully for a planner-proven empty source without completing that job. This is a remaining lifecycle gap after #62282 / #62889. Suggested triage: FE / INSERT / memory leak, with high priority given the reported master-FE availability impact. The issue currently has no labels or assignee.
Verified in code
I checked the configured local repository at 4.1.3 (commit 7126cf65d96e) and 4.1.5-release (917b20be8387), and fetched the relevant upstream master files at 13cff7ff484596f29aa1381750e906db3c8bb704 (2026-11-16). This was static investigation; I did not run the SQL against a cluster or modify source code.
- In 4.1.3, ordinary OLAP INSERT SELECT passes
needRegister = jobId != -1; the base constructor immediately registers the job.LoadJob.stateinitially equalsPENDING. Registration retains it in both the ID map and the database/label index. See executor selection, constructor, and registration/completion. - For the empty OLAP path,
initPlanskips transaction creation, andrunInternalreturns before either execution method. OLAP inheritsshouldExecuteEmptyInsert() == false. Consequently, neither successful completion bookkeeping nor failure bookkeeping runs. The 4.1.5-release path has the same gap. See 4.1.3 transaction gate and 4.1.5 early return. - Current master still registers before the
requiresTransaction()return. For an ordinary empty OLAP source without stream offset updates, this predicate is false. - Normal retention cannot reclaim these entries:
isExpiredrejects unfinished jobs, while count-based cleanup selects only completed jobs. If stuck entries alone exceed the threshold, that loop exhausts all completed jobs present in this manager. Metrics aggregation also traverses the retained jobs. Registration does not journal the job; completion does, which is consistent with the reported master-only growth and restart reset.
The production growth rate, retained bytes per job, GC pauses, and audit correlation remain reporter-provided observations, not independently measured results. The mechanism is sufficient for triage, but does not prove that every pending job or every pause has this cause. The problematic boundary is the physical empty plan, rather than LIST partitioning specifically. An executed query that happens to return zero rows follows a different lifecycle.
Recommended fix and validation
- Prefer an OLAP-specific completion path for the successful no-op that finalizes an already registered job as
FINISHED, with zero-row statistics and normal terminal timestamps/persistence. Alternatively, suppress registration for inserts that will take the no-transaction return, if omitting their SHOW LOAD history is accepted. - Do not simply invoke the existing OLAP
onComplete()orafterExec()unchanged: no transaction was opened (txnId == -1),onComplete()expects a real transaction, and the executor's initial transaction status isABORTED. Preserve a correct successful client response without fabricating a committed transaction. Keep intentional non-registration for VALUES, internal group commit, and external executors. - Preserve empty-source side effects: 4.1.x has external overwrite handling, and master requires a transaction for stream offset updates even with no output rows. A blanket empty-source skip would break those semantics.
- Extend
regression-test/suites/load_p0/insert/test_insert_statistic.groovywith repeated missing-LIST-partition inserts and a constant-false source. Assert the INSERT plan is empty and each uniquely labeled job becomes terminal (or is absent under the alternate design), with no residual PENDING growth. Cover an executed zero-row query, ordinary success/failure, and the existing empty-source side-effect cases. Validate cleanup and, if recording finished jobs, replay after restart. Backport after testing each affected branch.
Treat an age-based PENDING cleaner as a separate change. Live INSERT jobs also remain PENDING until completion, so age alone does not establish that an entry is orphaned. Lowering retention or increasing the count threshold will not remove the stuck entries.
Remaining evidence / next steps
The supplied reproducer is enough to start a regression and PR; a full production dump is not a prerequisite. Please add the exact FE build hash, relevant session settings (especially group commit), the full EXPLAIN INSERT INTO ... SELECT ... output, and uniquely labeled SHOW LOAD results plus before/after master PENDING counts from an otherwise quiet reproduction. These confirm that the actual INSERT selects the claimed executor and physical plan. A redacted heap dominator/class-histogram comparison and time-aligned GC logs would help quantify retained memory and pause attribution if needed.
For temporary prevention, skipping a plain INSERT whose source is authoritatively known to be empty avoids this path. A separate EXPLAIN can become stale when source data or partitions change, so it should not become a general correctness rule. It also does not reclaim existing entries. The reporter's willingness to submit a PR is appropriate; the missing regression should accompany it.