AXR: Reusing Intermediate Results for LLM Agents in PostgreSQL

Under review, 2026

Status: Manuscript under review · PDF: Download

Author

Runguo Li (single author).

Abstract

LLM agents answer analytical questions by exploring databases through SQL, and they are commonly run several times per question for reliability. On large data, the database then takes a large share of the agents’ time, and much of its work is redundant: attempts repeat their siblings’ statements, often while these are still running, and recompute the expensive parts of their own earlier statements under new statement text.

AXR is a PostgreSQL extension that materializes the results of plan subtrees as queries run and substitutes them into later plans. Its resolved signatures bind the run-time parameters of PostgreSQL’s parameterized nested loops and sub-query plans to the expressions they carry, so the subtrees that dominate agent queries can be matched. A statement can wait for a result that a concurrent attempt is still building, without risk of deadlock. A result is kept only if recomputing it costs more than reading it back, and reuse stays correct under concurrent writes through the same server.

Key Findings

  • Replaying twelve workloads recorded from one agent with two LLMs, AXR reduces database time by 6.5–51.0% at TPC-H scale factor 10 and by 23.9% on a TPC-H workload at scale factor 100.
  • Where attempts converge, a statement cache that shares running statements obtains most of this saving (21.6% at scale factor 100); reusing subtrees adds 21.3–23.0 points on every recording of one held-out set of TPC-DS questions, but only 2.0–8.9 on a second.
  • In 776,114 checked statement executions and 1,958 random queries compared value by value, AXR returned no wrong result.

Full text: Download the PDF

Recommended citation: Runguo Li. (2026). "AXR: Reusing Intermediate Results for LLM Agents in PostgreSQL." Manuscript under review.
Download Paper | Download Bibtex