db2 针对如下SQL如何优化索引,求大神指教,
其中F_REL_PIN_PERSON_BASE_MID九百万数据量F_REL_PIN_PERSON_BASE_MID_TMP四百万数据量SELECTI_DNO,I_DTY...
其中F_REL_PIN_PERSON_BASE_MID 九百万数据量
F_REL_PIN_PERSON_BASE_MID_TMP 四百万数据量
SELECT I_DNO,
I_DTYPE,
NAME,
GENDER,
CASE
WHEN BIRTH IS NOT NULL AND BIRTH <> '' THEN
BIRTH
ELSE
(SELECT BIRTH
FROM F_REL_PIN_PERSON_BASE_MID B
WHERE BIRTH IS NOT NULL
AND BIRTH <> ''
AND A.I_DNO = B.I_DNO
ORDER BY TABLE_ORDER ASC,
RECORD_TIME DESC FETCH FIRST 1 ROWS ONLY)
END BIRTH,
CASE
WHEN PHONE IS NOT NULL AND PHONE <> '' THEN
PHONE
ELSE
(SELECT PHONE
FROM F_REL_PIN_PERSON_BASE_MID B
WHERE PHONE IS NOT NULL
AND PHONE <> ''
AND A.I_DNO = B.I_DNO
ORDER BY TABLE_ORDER ASC,
RECORD_TIME DESC FETCH FIRST 1 ROWS ONLY)
END PHONE,
CASE
WHEN CELL_PHONE IS NOT NULL AND CELL_PHONE <> '' THEN
CELL_PHONE
ELSE
(SELECT CELL_PHONE
FROM F_REL_PIN_PERSON_BASE_MID B
WHERE CELL_PHONE IS NOT NULL
AND CELL_PHONE <> ''
AND A.I_DNO = B.I_DNO
ORDER BY TABLE_ORDER ASC,
RECORD_TIME DESC FETCH FIRST 1 ROWS ONLY)
END CELL_PHONE,
HOUSEHOLD_TYPE,
AVAILABLY_TAG,
HOUSEHOLD_REGION,
UNIQUE_PERSON_ID,
CURRENT TIMESTAMP AS LOAD_ODS_TIMESTAMP
FROM F_REL_PIN_PERSON_BASE_MID_TMP A 展开
F_REL_PIN_PERSON_BASE_MID_TMP 四百万数据量
SELECT I_DNO,
I_DTYPE,
NAME,
GENDER,
CASE
WHEN BIRTH IS NOT NULL AND BIRTH <> '' THEN
BIRTH
ELSE
(SELECT BIRTH
FROM F_REL_PIN_PERSON_BASE_MID B
WHERE BIRTH IS NOT NULL
AND BIRTH <> ''
AND A.I_DNO = B.I_DNO
ORDER BY TABLE_ORDER ASC,
RECORD_TIME DESC FETCH FIRST 1 ROWS ONLY)
END BIRTH,
CASE
WHEN PHONE IS NOT NULL AND PHONE <> '' THEN
PHONE
ELSE
(SELECT PHONE
FROM F_REL_PIN_PERSON_BASE_MID B
WHERE PHONE IS NOT NULL
AND PHONE <> ''
AND A.I_DNO = B.I_DNO
ORDER BY TABLE_ORDER ASC,
RECORD_TIME DESC FETCH FIRST 1 ROWS ONLY)
END PHONE,
CASE
WHEN CELL_PHONE IS NOT NULL AND CELL_PHONE <> '' THEN
CELL_PHONE
ELSE
(SELECT CELL_PHONE
FROM F_REL_PIN_PERSON_BASE_MID B
WHERE CELL_PHONE IS NOT NULL
AND CELL_PHONE <> ''
AND A.I_DNO = B.I_DNO
ORDER BY TABLE_ORDER ASC,
RECORD_TIME DESC FETCH FIRST 1 ROWS ONLY)
END CELL_PHONE,
HOUSEHOLD_TYPE,
AVAILABLY_TAG,
HOUSEHOLD_REGION,
UNIQUE_PERSON_ID,
CURRENT TIMESTAMP AS LOAD_ODS_TIMESTAMP
FROM F_REL_PIN_PERSON_BASE_MID_TMP A 展开
2013-05-10
展开全部
F_REL_PIN_PERSON_BASE_MID_TMP 四百万数据量,要全量查出来,以九百万数据量的
F_REL_PIN_PERSON_BASE_MID表作为子表,这个SQL对于什么数据都一个灾难,用一个查询SQL搞掉一个数据库指的这是这种SQL。
首先,要知道你需要什么数据,不可能需要 F_REL_PIN_PERSON_BASE_MID_TMP表里的全部数据吧,查询条件尽量选数据离散度高的字段,并用上索引,男女之类的字段就是加上索引过滤度能有多高呢?
其次是在子表的900万数据中查生日、电话,我不知道是出于什么目的要把数据这样存。
最后,就事说事,这个SQL我看到的能建索引的也就A.I_DNO = B.I_DNO这个条件了,两个分别创建I_DNO索引。
希望对你有帮助
F_REL_PIN_PERSON_BASE_MID表作为子表,这个SQL对于什么数据都一个灾难,用一个查询SQL搞掉一个数据库指的这是这种SQL。
首先,要知道你需要什么数据,不可能需要 F_REL_PIN_PERSON_BASE_MID_TMP表里的全部数据吧,查询条件尽量选数据离散度高的字段,并用上索引,男女之类的字段就是加上索引过滤度能有多高呢?
其次是在子表的900万数据中查生日、电话,我不知道是出于什么目的要把数据这样存。
最后,就事说事,这个SQL我看到的能建索引的也就A.I_DNO = B.I_DNO这个条件了,两个分别创建I_DNO索引。
希望对你有帮助
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询