Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-40133

Add Partial Result Cache for repeated nested-loop and correlated subquery execution

    XMLWordPrintable

Details

    Description

      Problem

      Repeated outer or dependent parameter values can make nested-loop joins and
      correlated subqueries execute the same inner plan many times within one
      statement. This is wasted work when the inner result for a parameter value is
      deterministic and can be reused safely.

      Proposed solution

      Add a statement-local Partial Result Cache, also called PTRC, above eligible inner work:

      • nested-loop join inner paths
      • deterministic dependent subqueries

      The cache is local to a single statement. It is not shared across statements,
      sessions, or transactions, and it does not change table data visibility.

      The implementation adds:

      • a new access path / iterator for partial result cache execution
      • optimizer_switch=partial_result_cache
      • PRC_SUBQUERY / NO_PRC_SUBQUERY and PRC_JOIN / NO_PRC_JOIN optimizer hints
      • bounded memory controls for statement-local cache storage
      • LRU eviction by complete key batch
      • pass-through bypass mode when caching is unsupported, not useful, or cannot
        initialize
      • EXPLAIN / EXPLAIN ANALYZE / optimizer trace diagnostics

      Unsupported or fallback cases

      Unsupported shapes keep the original plan or enter pass-through bypass mode.
      Examples include non-deterministic expressions, unsupported dependent subquery
      shapes, BLOB/TEXT cache keys, const-only paths, and low estimated or runtime
      hit-ratio cases.

      Correctness

      The cache preserves scalar, EXISTS, IN, ANY, and ALL correlated-subquery
      semantics by storing result item state, no-match state, and NULL state where
      needed.

      Validation

      The current PTRC branch has focused MTR coverage for hints, nested-loop joins,
      correlated subqueries, diagnostics, acceptance behavior, semantics, error paths,
      fault injection, and follow-up regression cases.

      Full MTR integration validation was run during the MySQL 8.0.46 PTRC port.
      PTRC-visible expected-result changes were reconciled. Known local non-PTRC
      environment failures were tracked separately.

      Local performance validation on repeated TPC-H Q17 workloads showed material
      improvement with identical query output hashes. These numbers are engineering
      evidence only, not official TPC-H results.

      Implementation branch / pull request

      Initial development branch:
      https://github.com/ZhuQingping/mysql-server/tree/support_partial_result_cache_8.0

      Licensing

      I submit this contribution under the New BSD License, also known as the
      3-clause BSD License.

      Attachments

        Activity

          People

            Unassigned Unassigned
            qingping Qingping Zhu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.