Re: Tid scan improvements

From: Edmund Horner <ejrh00(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: David Rowley <david(dot)rowley(at)2ndquadrant(dot)com>, Tomas Vondra <tomas(dot)vondra(at)2ndquadrant(dot)com>, PostgreSQL Developers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Tid scan improvements
Date: 2019-01-15 03:47:09
Message-ID: CAMyN-kDvdcpUjTD5nSxhLV8+77+-qQ-Ug8UJcux-HCoK9zqJJA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Sat, 22 Dec 2018 at 07:10, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> BTW, with respect to this bit in 0001:
>
> @@ -1795,6 +1847,15 @@ nulltestsel(PlannerInfo *root, NullTestType
> nulltesttype, Node *arg,
> return (Selectivity) 0; /* keep compiler quiet */
> }
> }
> + else if (vardata.var && IsA(vardata.var, Var) &&
> + ((Var *) vardata.var)->varattno ==
> SelfItemPointerAttributeNumber)
> + {
> + /*
> + * There are no stats for system columns, but we know CTID is
> never
> + * NULL.
> + */
> + selec = (nulltesttype == IS_NULL) ? 0.0 : 1.0;
> + }
> else
> {
> /*
>
> I'm not entirely sure why you're bothering; surely nulltestsel is
> unrelated to what this patch is about? And would anybody really
> write "WHERE ctid IS NULL"?
>

I found that it made a difference with selectivity of range comparisons,
because clauselist_selectivity tries to correct for it (clausesel.c:274):

s2 = rqlist->hibound + rqlist->lobound - 1.0

/* Adjust for double-exclusion of NULLs */
s2 += nulltestsel(root, IS_NULL, rqlist->var,
varRelid, jointype, sjinfo);

It was adding DEFAULT_UNK_SEL = 0.005 to the selectivity, which (while not
major) did make the selectivity less accurate.

However, if we do think it's worth adding code to cover this case,
> I wouldn't make it specific to CTID. *All* system columns can be
> assumed not null, see heap_getsysattr().
>
I guess we could have a standalone patch to add this for all system columns?

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2019-01-15 03:54:47 Re: Tid scan improvements
Previous Message Michael Paquier 2019-01-15 03:42:10 Re: could recovery_target_timeline=latest be the default in standby mode?