Re: Optional skipping of unchanged relations during ANALYZE?

From: VASUKI M <vasukianand0119(at)gmail(dot)com>
To: Ilia Evdokimov <ilya(dot)evdokimov(at)tantorlabs(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Christoph Berg <myon(at)debian(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Rowley <dgrowleyml(at)gmail(dot)com>, Robert Treat <rob(at)xzilla(dot)net>
Subject: Re: Optional skipping of unchanged relations during ANALYZE?
Date: 2026-01-21 09:37:01
Message-ID: CAE2r8H5Gsfs4REdo=Phj2GUv18Q5fsy-CBq0jbXyjrK1V-P5ag@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi Hackers,

As discussed in the recent thread, I’m sharing an initial v1 patch
introducing an opt-in SMART mode for ANALYZE.

When ANALYZE (SMART) is specified, relations that have not been modified
since their last analyze are skipped, based on existing pg_stat counters
(n_mod_since_analyze = 0). Relations without existing statistics are
still analyzed normally. The default ANALYZE behavior remains unchanged.

The primary goal of this patch is to reduce unnecessary work when
running ANALYZE over many mostly-static tables, while keeping the
behavior strictly opt-in.

Scope of this v1 patch:
- Uses existing pg_stat statistics only
- Does not skip relations that were never analyzed before
- Includes regression tests demonstrating that only modified tables are
re-analyzed
- Partitioned tables, inheritance, foreign tables,extended statistics and
other edge cases are intentionally not handled yet; I plan to look into
those in follow-up work based on feedback

Example usage / how to observe behavior:

SET client_min_messages = debug1;

ANALYZE (SMART);
ANALYZE (SMART, VERBOSE);

ANALYZE (SMART) table1;
ANALYZE (SMART) table1, table2;
VACUUM(SMART);

Thanks for your time and review.

Best regards,
Vasuki M
C-DAC,Chennai

Attachment Content-Type Size
v1-0001-ANALYZE-add-optional-smart-mode-to-skip-unchanged-relations.patch text/x-patch 8.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Christoph Berg 2026-01-21 09:44:45 Re: Optional skipping of unchanged relations during ANALYZE?
Previous Message Akshay Joshi 2026-01-21 09:31:44 Re: [PATCH] Add pg_get_database_ddl() function to reconstruct CREATE DATABASE statement