开发写了一个语句使用了connect by level函数
SELECT DISTINCT
CTMID FROM
(
SELECT CTMID,
REGEXP_SUBSTR(FLTUSERIDSTR, ‘[^;]+’, 1, l) AS userid
FROM s_userinfo,(SELECT LEVEL l FROM DUAL CONNECT BY LEVEL<=300) b
WHERE l <= LENGTH(FLTUSERIDSTR) - LENGTH(regexp_replace(FLTUSERIDSTR, ‘;’, ‘’)) + 1
)
GROUP BY CTMID, USERID HAVING LENGTH(USERID) > 10;
此语句我添加了hint
SELECT DISTINCT
CTMID FROM
(
SELECT /+use_hash(a,b)/ CTMID,
REGEXP_SUBSTR(FLTUSERIDSTR, ‘[^;]+’, 1, l) AS userid
FROM s_userinfo a,(SELECT LEVEL l FROM DUAL CONNECT BY LEVEL<=300) b
WHERE l <= LENGTH(FLTUSERIDSTR) - LENGTH(regexp_replace(FLTUSERIDSTR, ‘;’, ‘’)) + 1
)
GROUP BY CTMID, USERID HAVING LENGTH(USERID) > 10;
执行计划依旧不会改变
不能hash的话效率太差20多分钟才能执行完毕
最后采用了use_merge函数
SELECT DISTINCT
CTMID FROM
(
SELECT /+leading(a) use_hash(b)/ CTMID,
REGEXP_SUBSTR(FLTUSERIDSTR, ‘[^;]+’, 1, l) AS userid
FROM s_userinfo a,(SELECT LEVEL l FROM DUAL CONNECT BY LEVEL<=300) b
WHERE l <= LENGTH(FLTUSERIDSTR) - LENGTH(regexp_replace(FLTUSERIDSTR, ‘;’, ‘’)) + 1
)
GROUP BY CTMID, USERID HAVING LENGTH(USERID) > 10;
七秒钟得到执行效果,速度已经翻了很多倍
最后翻阅文档得出
1.Nested Loops Join支持大于,小于,不等,LIKE等连接条件,可以说没有受到任何限制!
2.Hash Join不支持大于,小于,不等,LIKE等连接条件!
3.Merge Sort Join不支持不等,LIKE等连接条件,却支持大于,小于的连接条件。