MAX/MIN optimization via rewrite (plus query rewrites generally) - Mailing list pgsql-hackers

From Mark Kirkwood
Subject MAX/MIN optimization via rewrite (plus query rewrites generally)
Date
Msg-id 41929AD1.4050603@coretech.co.nz
Whole thread Raw
Responses Re: MAX/MIN optimization via rewrite (plus query rewrites generally)  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: MAX/MIN optimization via rewrite (plus query rewrites generally)  ("Jim C. Nasby" <decibel@decibel.org>)
Re: MAX/MIN optimization via rewrite (plus query  (Simon Riggs <simon@2ndquadrant.com>)
Re: MAX/MIN optimization via rewrite (plus query rewrites  (Mark Kirkwood <markir@coretech.co.nz>)
List pgsql-hackers
I am looking at implementing this TODO item. e.g. (max case):

rewrite
SELECT max(foo) FROM bar
as
SELECT foo FROM bar ORDER BY foo DESC LIMIT 1
if there is an index on bar(foo)

Suggestions about the most suitable point in the parser/planner stage to 
perform this sort of rewrite would be most welcome! (as this would be my 
first non trivial getting of hands dirty in the code).

My initial thoughts revolved around extending the existing RULE system 
to be able to handle more general types of rewrite - like conditionals 
in SELECT rules and rewrites that change elements of the query other 
than the target relation.

Planning for future note: I would like whatever mechanism that is added 
for this MAX/MIN stuff to be amenable to more subtle things like 
aggregate navigation (see R.Kimball's article 
http://www.dbmsmag.com/9608d54.html).

regards

Mark


pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Beta time early next week
Next
From: Andrew Sullivan
Date:
Subject: Re: Increasing the length of