On 2024-Jan-23, David Rowley wrote: > Add better handling of redundant IS [NOT] NULL quals > > Until now PostgreSQL has not been very smart about optimizing away IS > NOT NULL base quals on columns defined as NOT NULL.
Hmm, what happens if a NOT NULL constraint is dropped and you have such a plan in plancache? As I recall, lack of a mechanism to invalidate such plans was the main reason for Postgres not to have this. One of the motivations for adding catalogued NOT NULL constraints was precisely to have an OID that you could use to cause plancache to invalidate such a plan. Does this new code add something like that? Admittedly I didn't read the threads or the patch, just skimmed for some clues, so I may have failed to notice it. But in the tests you added I don't see any ALTER TABLE DROP CONSTRAINT. (Similarly, allowing GROUP BY to ignore columns not in the GROUP BY, when a UNIQUE constraint exists and all columns are NOT NULL; currently we allow that for PRIMARY KEY, but if you have the NOT NULL constraint OIDs to cue the plan invalidation would let that case to be implemented as well.) -- Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/ "Por suerte hoy explotó el califont porque si no me habría muerto de aburrido" (Papelucho)