pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Rowley <drowley@postgresql.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow Memoize to operate in binary comparison mode
Date: Tue, 23 Nov 2021 21:07:25 +0000
Message-ID: <E1mpd0f-0000q6-8f@gemulon.postgresql.org> (raw)

Allow Memoize to operate in binary comparison mode

Memoize would always use the hash equality operator for the cache key
types to determine if the current set of parameters were the same as some
previously cached set.  Certain types such as floating points where -0.0
and +0.0 differ in their binary representation but are classed as equal by
the hash equality operator may cause problems as unless the join uses the
same operator it's possible that whichever join operator is being used
would be able to distinguish the two values.  In which case we may
accidentally return in the incorrect rows out of the cache.

To fix this here we add a binary mode to Memoize to allow it to the
current set of parameters to previously cached values by comparing
bit-by-bit rather than logically using the hash equality operator.  This
binary mode is always used for LATERAL joins and it's used for normal
joins when any of the join operators are not hashable.

Reported-by: Tom Lane
Author: David Rowley
Discussion: https://postgr.es/m/3004308.1632952496@sss.pgh.pa.us
Backpatch-through: 14, where Memoize was added

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/e502150f7d0be41e3c8784be007fa871a32d8a7f

Modified Files
--------------
contrib/postgres_fdw/expected/postgres_fdw.out |  3 +-
src/backend/commands/explain.c                 |  3 +
src/backend/executor/nodeMemoize.c             | 92 ++++++++++++++++++++-----
src/backend/nodes/copyfuncs.c                  |  1 +
src/backend/nodes/outfuncs.c                   |  2 +
src/backend/nodes/readfuncs.c                  |  1 +
src/backend/optimizer/path/joinpath.c          | 38 +++++++++--
src/backend/optimizer/plan/createplan.c        | 10 ++-
src/backend/optimizer/util/pathnode.c          |  4 +-
src/backend/utils/adt/datum.c                  | 52 ++++++++++++++
src/include/nodes/execnodes.h                  |  2 +
src/include/nodes/pathnodes.h                  |  2 +
src/include/nodes/plannodes.h                  |  2 +
src/include/optimizer/pathnode.h               |  1 +
src/include/utils/datum.h                      |  8 +++
src/test/regress/expected/join.out             | 28 +++++---
src/test/regress/expected/memoize.out          | 93 ++++++++++++++++++++++++--
src/test/regress/expected/subselect.out        |  3 +-
src/test/regress/sql/memoize.sql               | 39 +++++++++++
19 files changed, 345 insertions(+), 39 deletions(-)



view thread (2+ messages)  latest in thread

Message-ID: <E1mpd0f-0000q6-8f@gemulon.postgresql.org>
Permalink:  ../E1mpd0f-0000q6-8f@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1mpd0f-0000q6-8f@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: drowley@postgresql.org
  Subject: Re: pgsql: Allow Memoize to operate in binary comparison mode
  In-Reply-To: <E1mpd0f-0000q6-8f@gemulon.postgresql.org>
  References: <E1mpd0f-0000q6-8f@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