× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Great question, Joe.

The answer is that your CTE rewrite will give a plan that is basically
identical to the one produced by use of the view. There are some
cases--generally for performance or due to things like UDFs with external
actions, etc.--when the optimizer can't/won't merge the CTEs or views into
the outer select, but in general, if you can see a way to do it (and
sometimes even when you can't), the optimizer is probably going to do it,
too.

Tim Clark
DB2 for IBM i

"MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxxxxxxxx> wrote on 05/16/2019
05:02:07 PM:

From: Joe Pluta <joepluta@xxxxxxxxxxxxxxxxx>
To: midrange-l@xxxxxxxxxxxxxxxxxx,
Date: 05/16/2019 05:02 PM
Subject: [EXTERNAL] Re: why data translate error when selecting from
view?
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxxxxxxxx>

Thatnks for that explanation, Tim. In a related question: do CTEs allow

me to effectively "hardcode" the order, causing the SQL engine to work
in my predefined sequence?

For example, if in this case I did this:

with t1 as (select * from contr where length(trim(cpcsid)) = 10),
t2 as (select a.cpcono cono, case ... end csno from t1)
select * from t2 where csno = 1346100

Would that force the SQL engine to create my T1 in its entirety (thus
skipping short fields) before then doing the select? Or is the engine
just so darned smart that it ignores my sequence and just optimizes me
into errors? Of course, upon further reflection, if
length(trim(cpcsid)) = 10, then no need to check for blanks, so no CASE
statement. But I digress...


On 5/16/2019 4:36 PM, Timothy P Clark wrote:
You can think of the query engine "inlining" the view into the final
select statement.

<...snip lots of relevant and cool stuff...>


Keeping in mind that SQL has no rules about predicate evaluation
order, it
should be clear that if the optimizer chooses to evaluate the 2nd
predicate before the first predicate, we can run into the error you're
seeing.


--
This is the Midrange Systems Technical Discussion (MIDRANGE-L) mailing
list
To post a message email: MIDRANGE-L@xxxxxxxxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: https://urldefense.proofpoint.com/v2/url?

u=https-3A__lists.midrange.com_mailman_listinfo_midrange-2Dl&d=DwIGaQ&c=jf_iaSHvJObTbx-

siA1ZOg&r=oCmVbiwufH6yM8U29GriOcB5LKDoEG8y1HZD-01RVtc&m=uIFIUpL4kLjo726zd1hGUB8znDqd5lwGjlGB_n14Gds&s=upUivQxU54IEPST7W6WD7ClY4OABHgBLq47FZQ9fPvQ&e=
or email: MIDRANGE-L-request@xxxxxxxxxxxxxxxxxx
Before posting, please take a moment to review the archives
at https://urldefense.proofpoint.com/v2/url?
u=https-3A__archive.midrange.com_midrange-2Dl&d=DwIGaQ&c=jf_iaSHvJObTbx-

siA1ZOg&r=oCmVbiwufH6yM8U29GriOcB5LKDoEG8y1HZD-01RVtc&m=uIFIUpL4kLjo726zd1hGUB8znDqd5lwGjlGB_n14Gds&s=9hUfo5-
Jsc8rw-Nc0PpdYV26783BHKMUqEKwpQr4JME&e=.

Please contact support@xxxxxxxxxxxx for any subscription related
questions.

Help support midrange.com by shopping at amazon.com with our affiliate
link:
https://urldefense.proofpoint.com/v2/url?
u=https-3A__amazon.midrange.com&d=DwIGaQ&c=jf_iaSHvJObTbx-

siA1ZOg&r=oCmVbiwufH6yM8U29GriOcB5LKDoEG8y1HZD-01RVtc&m=uIFIUpL4kLjo726zd1hGUB8znDqd5lwGjlGB_n14Gds&s=ryY7pNASzUnVB0hx1rBpE2qPcN3fHc375U4UJD2dmrk&e=




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.