Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What happens to unused common table expressions?

6 views
Skip to first unread message

Roy Hann

unread,
Jan 4, 2012, 2:14:24 PM1/4/12
to
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?

--
Roy

UK Ingres User Association Conference 2012 will be on Tuesday June 19 2012.
The latest information is available from www.uk-iua.org.uk.


Karl Schendel

unread,
Jan 4, 2012, 6:07:30 PM1/4/12
to Ingres and related product discussion forum

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 trust your holidays were merry ... ours were generally quite nice.

Karl


Martin Bowes

unread,
Jan 5, 2012, 3:26:16 AM1/5/12
to Ingres and related product discussion forum
Example query?

Marty
_______________________________________________
Info-Ingres mailing list
Info-...@kettleriverconsulting.com
http://ext-cando.kettleriverconsulting.com/mailman/listinfo/info-ingres


Roy Hann

unread,
Jan 5, 2012, 5:41:49 AM1/5/12
to
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.
0 new messages