×
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.
I'm trying to suss out the performance issues in a very complex view,
and Visual Explain pointe me to this piece. 4 tables, UNIONed together
as a CTE. VE tells me that the UDFs are the culprit, but that makes no
sense as the exact same UDFs run in .001 over the exact same tables when
I run the 4 UNIONs alone.
This runs in milliseconds:
SELECT 'SOC' FILESOURCE, SOC.LOCNO LOCNO, SOC.SOCSEC SOCSEC,
SOC.FLNM3 || SOC.FLNM24 NAME, SOC.LSTNAM,
SOC.STREET, SOC.ADDR2, SOC.CITY, SOC.STATE, SOC.ZIP, SOC.ZIPPT2,
SOC.MEMBCD, DONOR, SOC.MEMSIN,
CAST(SOC.RFDLT AS CHAR(1)) RFDLT, SOC.NSTMEM, SOC.AFTMEM, SOC.LEVEL,
CVTNMDYTONUSA(BDAY, '1') DOB, TELENO, SEX,
SENDST,
CONDST, SOC.AD, LD, SOC.COUNTY, SDCODE, PRTYRG, REGSTD, RETCNL,
CAST(SOC.NMSUFX AS CHAR(10)) NMSUFX, MMDDYY2YYYYMMDD(SOC.DATE) DATE,
BLDGNO,
COALESCE(
(SELECT BLDNAME
FROM EMRBUILD
WHERE LOCAL = SOC.LOCNO AND BLDNUM = BLDGNO
ORDER BY LENGTH(TRIM(BLDNAME)) DESC
FETCH FIRST 1 ROWS ONLY), '') BUILDNAME,
CURPAY, ELEDST
FROM SOCMST SOC
UNION ALL
SELECT 'UUP' FILESOURCE, CAMP1 CONCAT CAMP2, UUP.SOCSEC,
UUP.FLNM3 || UUP.FLNM24 NAME, UUP.LSTNAM,
UUP.STREET, UUP.ADDR2, UUP.CITY, UUP.STATE, UUP.ZIP, UUP.ZIPPT2,
UUP.MEMBCD, DONOR, UUP.MEMSIN,
CAST(' ' AS CHAR(1)), UUP.NSTMEM, UUP.AFTMEM, UUP.LEVEL,
CVTNMDYTONUSA(UUP.BIRTHD, '1') DOB, TELENO, SEX,
DIGITS(SENATE),
UUP.CD, DIGITS(UUP.AD), SUBSTR(WARD, 1, 2), UUP.COUNTY, SDCODE, PRTYRG,
REGSTD, '',
CAST(' ' AS CHAR(10)), MMDDYY2YYYYMMDD(UUP.TRANDT ),
0, '' BUILDNAME, CURPAY, ED
FROM UUPMSTR UUP
WHERE MEMBCD <> 'C'
UNION ALL
SELECT 'PSC' FILESOURCE, PSC.LOCNO, PSC.SOCSEC,
PSC.FLNM3 || PSC.FLNM24 NAME, PSC.LSTNAM,
PSC.STREET, PMST.NOST2, PSC.CITY, PSC.STATE, PSC.ZIP, ZIPPT2,
PSC.MEMBCD, DONOR, PSC.MEMSIN,
CAST(' ' AS CHAR(1)), PSC.NSTMEM, PSC.AFTMEM, PSC.LEVEL,
CVTNMDYTONUSA(PMST.DOB, '1') DOB, PSC.TELENO, PSC.SEX,
CASE WHEN HEX(SN) <> '4040' THEN DIGITS(SN) ELSE ' ' END,
CONDST, DIGITS(ASMDST), SUBSTR(WARD, 1, 2), PSC.COUNTY, SDCODE, PRTYRG,
REGSTD, '',
CAST(' ' AS CHAR(10)), MMDDYY2YYYYMMDD(PSC.DATE ),
BLDGNO, '' BUILDNAME, CURPAY, BLK3
FROM PSCSOC PSC
LEFT JOIN PSCMST PMST ON PSC.SOCSEC = PMST.SOC
Wrapping it in a CTE takes 2 minutes.
with temp as (
-- the exact same 4 UNIONs
)
select *
from temp
Visual Explain is correct in that removing the UDFs does in fact speed
the thing up. The question is this: Why does wrapping this an a CTE
slow it down?
As an Amazon Associate we earn from qualifying purchases.
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.