Karl Schendel wrote:
> On Jan 4, 2012, at 2:14 PM, Roy Hann wrote:
>
>> I could just try this to see, but I'm feeling lazy and someone probably
>> knows the answer.
>>
>> If I write a query with one or more common table expressions to which I
>> don't actually refer in the query, do they just get pruned off or do
>> they get executed regardless?
>
> I'm guessing they get pruned off, but I'd have to try it to find out.
> I'm lazy too.
I summoned enough energy to do the upgrade I needed to apply before just
trying the query for myself.
I can now tell you that the extraneous CTEs *are* pruned, at least in
this simple test on a toy database:
INGRES TERMINAL MONITOR Copyright 2011 Ingres Corporation
Ingres Microsoft Windows Version II 10.1.0 (int.w32/121) login
Thu Jan 05 10:30:59 2012
Enter \g to execute commands, "help help\g" for help, \q to quit
continue
* set qep;
*
* with smallorders ( ordernr ) as
* (
* select ordernr
* from orderitems
* group by ordernr
* having count(*) < 3
* )
* select count(*) from customers;
* \g
Executing . . .
********************************************************************
QUERY PLAN 1,2, no timeout, of simple aggregate
aggregate expression -> count(*)
Proj-rest
Heap
Pages 36 Tups 10000
D64 C100
/
customers
Hashed(NU)
Pages 514 Tups 10000
********************************************************************
+-------------+
|col1 |
+-------------+
| 10000|
+-------------+
(1 row)
continue
*
> I trust your holidays were merry ... ours were generally quite nice.
"Quite nice" would be about as far as I'd go too.