Re: Is the query engine always smart enough to know when to generate an internal CTE on a query?
Infodorado InfoDorado via MIDRANGE-L <[email protected]>
| Newsgroups | gmane.comp.hardware.ibm.midrange |
|---|---|
| Message-ID | <[email protected]> |
I prefer to make CTE explicit and detailed. Auto-generated query
statements and generated algorithms may look very pretty and neat, but you
have to look under the hood to make sure it's truly fit for purpose
I do like the suggestions for possible better query statements, but I take
a good look and do a good testing before production.
On 08/07/2026 7:14 AM CST Peter Lunde <[1][email protected]>
wrote:
Hi Dan,
I think an explicit CTE is worth a try.
Best Regards,
Peter.
647-456-3124
[2][email protected]
________________________________
From: MIDRANGE-L <[3][email protected]> on behalf of
Dan Bale via MIDRANGE-L <[4][email protected]>
Sent: Thursday, August 06, 2026 17:23
To: Midrange Systems Technical Discussion
<[5][email protected]>
Cc: Dan Bale <[6][email protected]>
Subject: Is the query engine always smart enough to know when to
generate an internal CTE on a query?
We've got a long-running query that has a tendency to get canceled
because it hits our temporary storage threshold.
The current table has a lot of conditions in the WHERE clause on the
primary table that greatly narrow the rows from that table. There are
also 15 left joins on that primary table. I've thought about modifying
the query to use a CTE on the primary table and move the conditions in
the WHERE clause to the CTE.
I'm just wondering if the query engine optimizes this anyway without the
explicit CTE. Thoughts?
- Dan Bale
*** CONFIDENTIALITY NOTICE: The information contained in this
communication may be confidential, and is intended only for the use of
the recipients named above. If the reader of this message is not the
intended recipient, you are hereby notified that any dissemination,
distribution, or copying of this communication, or any of its contents,
is strictly prohibited. If you have received this communication in
error, please return it to the sender immediately and delete the
original message and any copy of it from your computer system. If you
have any questions concerning this message, please contact the sender.
***
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: [7][email protected]
To subscribe, unsubscribe, or change list options,
visit: [8]https://lists.midrange.com/mailman/listinfo/midrange-l
or email: [9][email protected]
Before posting, please take a moment to review the archives
at [10]https://archive.midrange.com/midrange-l.
Please contact [11][email protected] for any subscription
related questions.
You can help support midrange.com by visiting
[12]https://donate.midrange.com and making a contribution.
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: [13][email protected]
To subscribe, unsubscribe, or change list options,
visit: [14]https://lists.midrange.com/mailman/listinfo/midrange-l
or email: [15][email protected]
Before posting, please take a moment to review the archives
at [16]https://archive.midrange.com/midrange-l.
Please contact [17][email protected] for any subscription
related questions.
You can help support midrange.com by visiting
[18]https://donate.midrange.com and making a contribution.
References
Visible links
1. mailto:[email protected]
2. mailto:[email protected]
3. mailto:[email protected]
4. mailto:[email protected]
5. mailto:[email protected]
6. mailto:[email protected]
7. mailto:[email protected]
8. https://lists.midrange.com/mailman/listinfo/midrange-l
9. mailto:[email protected]
10. https://archive.midrange.com/midrange-l
11. mailto:[email protected]
12. https://donate.midrange.com/
13. mailto:[email protected]
14. https://lists.midrange.com/mailman/listinfo/midrange-l
15. mailto:[email protected]
16. https://archive.midrange.com/midrange-l
17. mailto:[email protected]
18. https://donate.midrange.com/
--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/midrange-l
or email: [email protected]
Before posting, please take a moment to review the archives
at https://archive.midrange.com/midrange-l.
Please contact [email protected] for any subscription related questions.
You can help support midrange.com by visiting https://donate.midrange.com and making a contribution.