说明 :
这个sql做的事情就是从union上sql语句查询一部分数据和从union下sql查询一部分数据。两部分数据查出合并。
以前正常执行。最近发现执行这sql.会一直执行,但是没结果。求大神告知其原因,万分感谢!!select a.*
--,prod.productid as pid
from (select b.gcid as cid, --[t_content_base_syn] 全局内容ID:lenth(datatype+(补零)+contentid)=20
b.DATATYPE as type, --[t_content_base_syn] 10:游戏,20:音乐,30:视频,40:动漫,50:阅读
g.musicid, --[T_MB_MUSIC_NEW_syn]歌曲ID
g.songname, --[T_MB_MUSIC_NEW_syn]歌曲名称
g.singer, --[T_MB_MUSIC_NEW_syn]歌手名称
p.pkg_id --[T_CONTENT_PACKAGE_syn]内容包ID,
--p.pkg_name --[T_CONTENT_PACKAGE_syn]内容包名称
from t_content_base_syn b, --统一内容信息表
T_MB_MUSIC_NEW_syn g, --音乐歌曲表
T_MB_SINGER_NEW_syn m , --歌手信息表
T_PKG_CONTENT_syn pc, --内容包和内容关联关系表
T_CONTENT_PACKAGE_syn p, --内容包信息表
filter_view v --渠道过滤视图
where b.DATATYPE = 20
and b.CONTENTID = g.musicid
and b.gcid = pc.gcid
and pc.pkg_id = p.pkg_id
and b.contentid = v.contentid
and (g.SINGERSID = m.sid or substr(g.SINGERSID,1,instr(g.singersid,'|')-1) = m.sid)
and v.datatype = 20) a,
t_product_syn prod
where a.pkg_id = prod.pcid
union
select k.*
from (select b.gcid as cid, --[t_content_base_syn] 全局内容ID:lenth(datatype+(补零)+contentid)=20
b.DATATYPE as type, --[t_content_base_syn] 10:游戏,20:音乐,30:视频,40:动漫,50:阅读
g.musicid, --[T_MB_MUSIC_NEW_syn]歌曲ID
g.songname, --[T_MB_MUSIC_NEW_syn]歌曲名称
g.singer, --[T_MB_MUSIC_NEW_syn]歌手名称
null as pkg_id --null
--null as pkg_name, --null
--prod.productid as pid --产品id
from t_content_base_syn b, --统一内容信息表
T_MB_MUSIC_NEW_syn g, --音乐歌曲表
T_MB_SINGER_NEW_syn m , --歌手信息表
t_product_syn prod, --产品信息表
filter_view v --渠道过滤视图
where b.DATATYPE = 20
and b.CONTENTID = g.musicid
and (g.SINGERSID = m.sid or substr(g.SINGERSID,1,instr(g.singersid,'|')-1) = m.sid)
and prod.pcid = b.gcid
and prod.ptype = 0
and b.contentid = v.contentid
and v.datatype = 20) k
这个sql做的事情就是从union上sql语句查询一部分数据和从union下sql查询一部分数据。两部分数据查出合并。
以前正常执行。最近发现执行这sql.会一直执行,但是没结果。求大神告知其原因,万分感谢!!select a.*
--,prod.productid as pid
from (select b.gcid as cid, --[t_content_base_syn] 全局内容ID:lenth(datatype+(补零)+contentid)=20
b.DATATYPE as type, --[t_content_base_syn] 10:游戏,20:音乐,30:视频,40:动漫,50:阅读
g.musicid, --[T_MB_MUSIC_NEW_syn]歌曲ID
g.songname, --[T_MB_MUSIC_NEW_syn]歌曲名称
g.singer, --[T_MB_MUSIC_NEW_syn]歌手名称
p.pkg_id --[T_CONTENT_PACKAGE_syn]内容包ID,
--p.pkg_name --[T_CONTENT_PACKAGE_syn]内容包名称
from t_content_base_syn b, --统一内容信息表
T_MB_MUSIC_NEW_syn g, --音乐歌曲表
T_MB_SINGER_NEW_syn m , --歌手信息表
T_PKG_CONTENT_syn pc, --内容包和内容关联关系表
T_CONTENT_PACKAGE_syn p, --内容包信息表
filter_view v --渠道过滤视图
where b.DATATYPE = 20
and b.CONTENTID = g.musicid
and b.gcid = pc.gcid
and pc.pkg_id = p.pkg_id
and b.contentid = v.contentid
and (g.SINGERSID = m.sid or substr(g.SINGERSID,1,instr(g.singersid,'|')-1) = m.sid)
and v.datatype = 20) a,
t_product_syn prod
where a.pkg_id = prod.pcid
union
select k.*
from (select b.gcid as cid, --[t_content_base_syn] 全局内容ID:lenth(datatype+(补零)+contentid)=20
b.DATATYPE as type, --[t_content_base_syn] 10:游戏,20:音乐,30:视频,40:动漫,50:阅读
g.musicid, --[T_MB_MUSIC_NEW_syn]歌曲ID
g.songname, --[T_MB_MUSIC_NEW_syn]歌曲名称
g.singer, --[T_MB_MUSIC_NEW_syn]歌手名称
null as pkg_id --null
--null as pkg_name, --null
--prod.productid as pid --产品id
from t_content_base_syn b, --统一内容信息表
T_MB_MUSIC_NEW_syn g, --音乐歌曲表
T_MB_SINGER_NEW_syn m , --歌手信息表
t_product_syn prod, --产品信息表
filter_view v --渠道过滤视图
where b.DATATYPE = 20
and b.CONTENTID = g.musicid
and (g.SINGERSID = m.sid or substr(g.SINGERSID,1,instr(g.singersid,'|')-1) = m.sid)
and prod.pcid = b.gcid
and prod.ptype = 0
and b.contentid = v.contentid
and v.datatype = 20) k
解决方案 »
- 命中率大于98%,还需要将某些基础数据表ALTER TABLE CACHE吗
- 请教:客户端浏览器无法打开oracle10g
- 如何将多行返回并成一行输出 (在线等 立即结)
- 触发器问题---在线等.有分啊.....
- 我在使用plsql 的execute immediate的时候,总是发现下面的问题
- 在一表中有一日期型字段,有数百条记录,日期格式为2004-4-10 12:20:19形式,怎么写SQL把日期改成2004-4-10形式
- oracle9i中,连接的进程不断增加,一直不释放。直到达到process限制
- 会话中的“长时间操作”是什么意思?
- DBMS_JOB包问题。100分求助!!
- 执行sqlplus /nolog ,提示段错误。。。。。。。
- 数据查询效率优化
- 如何能够得出如下结果
网络还行,可以说正常。这种也可以排除。数据吧,对于orcle其实也不算多。
备注:以前确实可以正常查询。过了一段时间现象就是这样一直执行没结果。还有其他原因造成的吗?
filter_view是个视图吧?另外,T_PKG_CONTENT_syn和T_CONTENT_PACKAGE_syn有多少数据呢?
union本身效率就不高
两个大数据集尽量不要union
============= filter_view ======================================
create or replace view filter_view as
select
distinct b.contentid,b.datatype
from t_product_syn p,--统一产品信息
v_package_channel c,--渠道
t_content_base_syn b,--统一内容信息
T_PKG_CONTENT_syn pc--内容包关联关系
where c.productid = p.productid --产品id
and p.ptype = 1
and p.pcid = pc.pkg_id--包id
and pc.gcid = b.gcid--全局id
and pc.del_flg = '1'
and c.channelid = '300000100001'
union
select distinct b.contentid, b.datatype
from t_product_syn p, --统一产品信息
v_package_channel c, --渠道
t_content_base_syn b, --统一内容信息
t_single_content_syn s --单品内容信息表关联关系
where c.productid = p.productid --产品id
and p.pcid = b.gcid
and p.ptype = 0
and b.gcid = s.gcid
and s.LINESTATUS = '0'
and c.channelid = '300000100001';====================整个sql语句=======================select distinct music.cid,music.type,music.musicid,music.songname,music.singer from (
select b.gcid as cid, --[t_content_base_syn] 全局内容ID:lenth(datatype+(补零)+contentid)=20
b.DATATYPE as type, --[t_content_base_syn] 10:游戏,20:音乐,30:视频,40:动漫,50:阅读
g.musicid, --[T_MB_MUSIC_NEW_syn]歌曲ID
g.songname, --[T_MB_MUSIC_NEW_syn]歌曲名称
g.singer, --[T_MB_MUSIC_NEW_syn]歌手名称
p.pkg_id --[T_CONTENT_PACKAGE_syn]内容包ID,
--p.pkg_name --[T_CONTENT_PACKAGE_syn]内容包名称
from t_content_base_syn b, --统一内容信息表
T_MB_MUSIC_NEW_syn g, --音乐歌曲表
T_MB_SINGER_NEW_syn m , --歌手信息表
T_PKG_CONTENT_syn pc, --内容包和内容关联关系表
T_CONTENT_PACKAGE_syn p, --内容包信息表
filter_view v, --渠道过滤视图
t_product_syn prod
where b.DATATYPE = 20
and b.CONTENTID = g.musicid
and b.gcid = pc.gcid
and p.pkg_id = prod.pcid
and pc.pkg_id = p.pkg_id
and b.contentid = v.contentid
and (g.SINGERSID = m.sid or substr(g.SINGERSID,1,instr(g.singersid,'|')-1) = m.sid)
and v.datatype = 20
union
select b.gcid as cid, --[t_content_base_syn] 全局内容ID:lenth(datatype+(补零)+contentid)=20
b.DATATYPE as type, --[t_content_base_syn] 10:游戏,20:音乐,30:视频,40:动漫,50:阅读
g.musicid, --[T_MB_MUSIC_NEW_syn]歌曲ID
g.songname, --[T_MB_MUSIC_NEW_syn]歌曲名称
g.singer, --[T_MB_MUSIC_NEW_syn]歌手名称
null as pkg_id --null
--null as pkg_name, --null
--prod.productid as pid --产品id
from t_content_base_syn b, --统一内容信息表
T_MB_MUSIC_NEW_syn g, --音乐歌曲表
T_MB_SINGER_NEW_syn m , --歌手信息表
t_product_syn prod, --产品信息表
filter_view v --渠道过滤视图
where b.DATATYPE = 20
and b.CONTENTID = g.musicid
and (g.SINGERSID = m.sid or substr(g.SINGERSID,1,instr(g.singersid,'|')-1) = m.sid)
and prod.pcid = b.gcid
and prod.ptype = 0
and b.contentid = v.contentid
and v.datatype = 20 )music
求大神们有什么好优化方法!!!!!1
Union
与
Union all 还是有区别的,
Union 会检查上下两个数据,并且只显示不同的数据,重复的数据就显示一次,你的情况会让前后的数据再一次进行比较,如果前后数据都挺多的话,会影响速度。
Union all 是不管不顾的把上下数据连接起来,重复了也不管。就少了最后一次匹配。
又是or 又是 substr ,instr, 想快,不容易啊。这些都没法用索引的。
2、查看等待事件,看看哪里产生了等待