plan cache vs regclass constants

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-hackers(at)postgreSQL(dot)org
Subject: plan cache vs regclass constants
Date: 2008-06-17 13:39:35
Message-ID: 19769.1213709975@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The example here
http://archives.postgresql.org/pgsql-novice/2008-06/msg00025.php
shows that we are failing to regenerate cached plans when a table
referenced by a regclass constant is removed. This is pretty minor
in the big scheme of things, but it's still annoying since there is
code in there that's explicitly intended to make that work (see
fix_scan_expr in setrefs.c). I looked into why not, and soon
realized that the example case really is 'tablename'::regclass::oid
(ie, a RelabelType node atop a Const) because the constant is an
argument to oideq(). So constant folding reduces that to just a
Const of type OID, and fix_scan_expr doesn't think it's interesting.

I see two ways this might be fixed:

1. Don't constant-fold this particular case. Costs: very ugly
special case in constant folding, and a tiny execution-time penalty.

2. Make fix_scan_expr treat Consts of type OID like regclass Consts.
Costs: some bogus additions to the list of relation OIDs a plan
depends on, which would occasionally result in unnecessary replans.

Anyone have a preference, or see a third way? I'm kind of leaning
to #1, but it sure is ugly.

regards, tom lane

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2008-06-17 13:49:15 Re: Reducing overhead for repeat de-TOASTing
Previous Message Andrew Dunstan 2008-06-17 13:23:40 Re: Crash in pgCrypto?