Мы создали представление SQL. Однако, когда я запрашиваю представление, требуется более 10 минут, чтобы вернуть одну запись. Видите ли вы какие-либо проблемы с видом? Как мы можем устранить проблему с производительностью? Есть ли лучшая практика для создания вида
CREATE VIEW [dbo].[vw_mytestview]
AS
SELECT
Table1.SL_DISPLAY_NAME, Table1.SL_ACCOUNT_TYPE, Table1.SL_FIRST_NAME,
Table1.SL_MIDDLE_NAME, Table1.SL_LAST_NAME,
Table1.SL_PRF_FIRST_NAME, Table1.SL_PRF_LAST_NAME,
Table1.SL_PRF_MIDDLE_NAME, Table1.SL_PRF_SECOND_LAST_NAME,
Table1.SL_PRI_FIRST_NAME, Table1.SL_PRI_LAST_NAME,
Table1.SL_PRI_MIDDLE_NAME, Table1.SL_PRI_SECOND_LAST_NAME,
Table1.LOCATION_DESCR, Table1.SL_WORK_PHONE, Table1.SL_WORK_EXTENSION,
Table2.EMAIL AS EMAIL_ADDR,
Table1.LOCATION_ADDRESS, Table1.LOCATION_ADDRESS1,
Table1.LOCATION_ADDRESS2, Table1.LOCATION_ADDRESS3,
Table1.LOCATION_ADDRESS4, Table1.LOCATION_ADDRESS_CITY,
Table1.LOCATION_CITY_CD, Table1.LOCATION_STATE_DESCR,
Table1.LOCATION_POSTAL_CD, Table1.C, Table1.CO,
Table1.LOCATION_COUNTRY_DESCR, Table1.SL_CELL_PHONE,
Table1.SL_FAX, Table1.SL_BUSINESS_TITLE, Table1.SL_DEPARTMENT,
Table1.SL_GD_ENTITY, Table1.COMPANY_DESCR,
Table1.SL_COUNSELOR_GPN, Table1.SL_ASSISTANT_GPN, Table1.GUI,
Table1.GPN, Table1.LPN, Table1.IND_SECTOR_DESCR,
Table1.LANG_CD, Table1.LANG_DESCR, Table1.LEAVE_DT, Table1.REHIRE_DT,
Table1.SL_LEGAL_ENTITY,
Table1.GEO_AREA_CD, Table1.MANAGE_AREA_DESCR,
Table1.COUNTRY_GROUPING_DESCR, Table1.SUB_AREA_DESCR,
Table1.LOCATION_CD, Table1.BU_CD, Table1.BU_DESCR, Table1.OU_CD,
Table1.OU_DESCR, Table1.MU_CD,
Table1.MU_DESCR, Table1.SMU_CD, Table1.SMU_DESCR, Table1.MC_CD,
Table1.MC_DESCR, Table1.SERVICE_LINE_CD,
Table1.SERVICE_LINE_DESCR, Table1.SUB_SERVICE_LINE_CD,
Table1.SUB_SERVICE_LINE_DESCR, Table1.SL_COMPANY_ID,
Table1.SL_DEPARTMENT_ID, Table1.SL_SUB_AREA, Table1.DELETE_FLAG,
Table1.SL_RANK_CD, Table1.SL_RANK_DESCR,
Table1.SL_EYCOMM, Table1.EMPL_STATUS, Table1.GBL_ASSIGNEE_IND,
Table1.SL_EXCL_INCL_FL, Table1.SL_MC_CTRY_2CHAR,
Table1.SL_IND_SEGMENT_CD, Table1.SL_GD_STATUS, Table1.SL_DOMAIN,
Table1.SL_MAILING_ADDR, Table1.SL_CODED_MAIL_ADDR,
Table1.START_DATE, Table1.HIRE_DT, Table1.DATETIME_STAMP,
Table2.samaccountname
FROM
dbo.mytesttable AS Table1
INNER JOIN
dbo.vw_otherone AS Table2 ON Table1.GPN COLLATE DATABASE_DEFAULT = Table2.GPN COLLATE DATABASE_DEFAULT
WHERE
(Table2.samaccountname IS NOT NULL)
AND (Table1.SL_DISPLAY_NAME IS NOT NULL)
AND (Table1.SL_ACCOUNT_TYPE IS NOT NULL)
AND (Table1.SL_FIRST_NAME IS NOT NULL)
AND (Table1.SL_LAST_NAME IS NOT NULL)
AND (Table1.C IS NOT NULL)
AND (Table1.SL_GD_ENTITY IS NOT NULL)
AND (Table1.GUI IS NOT NULL)
AND (Table1.GPN IS NOT NULL)
AND (Table1.LPN IS NOT NULL)
AND (Table1.EMPL_STATUS IS NOT NULL)
AND (Table2.samaccountname <> '')
AND (Table1.SL_DISPLAY_NAME <> '')
AND (Table1.SL_ACCOUNT_TYPE <> '')
AND (Table1.SL_FIRST_NAME <> '')
AND (Table1.SL_LAST_NAME <> '')
AND (Table1.C <> '')
AND (Table1.SL_GD_ENTITY <> '')
AND (Table1.GUI <> '')
AND (Table1.GPN <> '')
AND (Table1.LPN <> '')
AND (Table1.EMPL_STATUS <> '')
GO