pgsql: Remove the restriction originally coded into - Mailing list pgsql-committers

From tgl@postgresql.org (Tom Lane)
Subject pgsql: Remove the restriction originally coded into
Date
Msg-id 20060428205750.1FA8811F60A2@postgresql.org
Whole thread Raw
List pgsql-committers
Log Message:
-----------
Remove the restriction originally coded into optimize_minmax_aggregates() that
MIN/MAX not be converted to use an index if the query WHERE clause contains
any volatile functions or subplans.

I had originally feared that the conversion might alter the behavior of such a
query with respect to a volatile function.  Well, so it might, but only in the
sense that the function would get evaluated at a subset of the table rows
rather than all of them --- and we have never made any such guarantee anyway.
(For instance, we don't refuse to use an index for an ordinary non-aggregate
query when one of the non-indexable filter conditions contains a volatile
function.)

The prohibition against subplans was because of worry that that case wasn't
adequately tested, which it wasn't, but it turns out to be possible to make
8.1 fail anyway:

regression=# select o.ten, (select max(unique2) from tenk1 i where ten = o.ten
or ten = (select f1 from int4_tbl limit 1)) from tenk1 o;
ERROR:  direct correlated subquery unsupported as initplan

This is due to bogus code in SS_make_initplan_from_plan (it's an initplan,
ergo it can't have any parParams).  Having fixed that, we might as well allow
subplans as well as initplans.

Modified Files:
--------------
    pgsql/src/backend/optimizer/plan:
        planagg.c (r1.13 -> r1.14)
        (http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/plan/planagg.c.diff?r1=1.13&r2=1.14)
        subselect.c (r1.105 -> r1.106)

(http://developer.postgresql.org/cvsweb.cgi/pgsql/src/backend/optimizer/plan/subselect.c.diff?r1=1.105&r2=1.106)

pgsql-committers by date:

Previous
From: Kris Jurka
Date:
Subject: Re: pgsql: Modify Solaris compiler build rules to use the cpp preprocessor,
Next
From: tgl@postgresql.org (Tom Lane)
Date:
Subject: pgsql: Remove the restriction originally coded into