pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Cache the result of converting now() to a struct pg_tm.
Date: Mon, 28 Sep 2020 16:05:19 +0000
Message-ID: <E1kMveR-0003pU-P6@gemulon.postgresql.org> (raw)

Cache the result of converting now() to a struct pg_tm.

SQL operations such as CURRENT_DATE, CURRENT_TIME, LOCALTIME, and
conversion of "now" in a datetime input string have to obtain the
transaction start timestamp ("now()") as a broken-down struct pg_tm.
This is a remarkably expensive conversion, and since now() does not
change intra-transaction, it doesn't really need to be done more than
once per transaction.  Introducing a simple cache provides visible
speedups in queries that compute these values many times, for example
insertion of many rows that use a default value of CURRENT_DATE.

Peter Smith, with a bit of kibitzing by me

Discussion: https://postgr.es/m/CAHut+Pu89TWjq530V2gY5O6SWi=OEJMQ_VHMt8bdZB_9JFna5A@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/0a87ddff5c83589e90de236bd55e6a19b017fe9a

Modified Files
--------------
src/backend/utils/adt/date.c     | 49 ++++++++++++++---------------
src/backend/utils/adt/datetime.c | 67 +++++++++++++++++++++++++++++++++-------
2 files changed, 80 insertions(+), 36 deletions(-)



Message-ID: <E1kMveR-0003pU-P6@gemulon.postgresql.org>
Permalink:  ../E1kMveR-0003pU-P6@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1kMveR-0003pU-P6@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Cache the result of converting now() to a struct pg_tm.
  In-Reply-To: <E1kMveR-0003pU-P6@gemulon.postgresql.org>
  References: <E1kMveR-0003pU-P6@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox