2025 年 7 月 23 日 星期三 晴
午后的阳光透过百叶窗在桌面上投下斑驳的光影,我百无聊赖地翻着桌上的数据库手册,指尖划过索引优化的章节时,聊天软件突然 “叮” 地一声弹出提示 —— 是某客户的技术支持请求。
“我们有一条 SQL 执行时报错,能不能帮忙看看?” 消息后面跟着一张报错截图。我随手点开回复 “稍等,我看看”,很快收到了更详细的说明:这条 SQL 是临时写的,用 PLSQL Developer 执行,原本是要统计些数据用于汇报,可每次运行都会弹出 ORA-00600 错误,括号里的参数固定是 [xtydty2ldi],后面跟着一串空值。
这种内部错误向来麻烦。普通的语法错误会明确指出哪行少了逗号、哪个表名拼错了,可 ORA-00600 更像数据库的 “暗语”,得从那些神秘参数里找线索。我让客户把完整 SQL 发过来,快速浏览时注意到:多层子查询嵌套着三张表的关联,里面有聚合函数统计、字符拼接,还有时间转换和 group by 分组 —— 这些都是很常规的操作,逻辑上看不出问题。
“这是临时取数的脚本,之前没这么用过。” 客户补充道。看来不是长期运行的程序突然出故障,更像是临时脚本触发了特定场景下的异常。我把 SQL 语句复制到本地编辑器里,准备先复现问题看看具体情况。
完整SQL语句:(注:此为示例,非真实表名)
select a.*
from (select day, TNO, count(1) task_count, sum(CW) as total_ton, sum(value) as total_mile
from (select a.TNO,
to_char(ING, 'yyyy-MM-dd') day,
b.CW,
c.VALUE
from truck.A a
left join truck.B b on a.CUSTNO = b.CUSTNO and a.CN = b.CN
left join truck.C c on c.FKID = 81 and c.APP_C = a.FT || ',' || a.ST
where a.IOT = '0'
and a.CS = 'F'
and IOGD >= timestamp '2025-07-01 00:00:00'
and IOGD < timestamp '2025-07-03 00:00:00')
group by TNO, day) a
left join truck.B b on a.TNO = b.TNO

问题处理步骤:
create table temp2025 as
select day, TNO, count(1) task_count, sum(CW) as total_ton, sum(value) as total_mile
from (select a.TNO,
to_char(ING, 'yyyy-MM-dd') day,
b.CW,
c.VALUE
from truck.A a
left join truck.B b on a.CUSTNO = b.CUSTNO and a.CN = b.CN
left join truck.C c on c.FKID = 81 and c.APP_C = a.FT || ',' || a.ST
where a.IOT = '0'
and a.CS = 'F'
and IOGD >= timestamp '2025-07-01 00:00:00'
and IOGD < timestamp '2025-07-03 00:00:00')
group by TNO, day;
select a.*
from temp2025 a
left join truck.B b on a.TNO = b.TNO;
alter session set "_disable_function_based_index"=true;
select a.*
from (select day, TNO, count(1) task_count, sum(CW) as total_ton, sum(value) as total_mile
from (select a.TNO,
to_char(ING, 'yyyy-MM-dd') day,
b.CW,
c.VALUE
from truck.A a
left join truck.B b on a.CUSTNO = b.CUSTNO and a.CN = b.CN
left join truck.C c on c.FKID = 81 and c.APP_C = a.FT || ',' || a.ST
where a.IOT = '0'
and a.CS = 'F'
and IOGD >= timestamp '2025-07-01 00:00:00'
and IOGD < timestamp '2025-07-03 00:00:00')
group by TNO, day) a
left join truck.B b on a.TNO = b.TNO;
select /*+ OPT_PARAM('_disable_function_based_index', 'true')a.*
from (select day, TNO, count(1) task_count, sum(CW) as total_ton, sum(value) as total_mile
from (select a.TNO,
to_char(ING, 'yyyy-MM-dd') day,
b.CW,
c.VALUE
from truck.A a
left join truck.B b on a.CUSTNO = b.CUSTNO and a.CN = b.CN
left join truck.C c on c.FKID = 81 and c.APP_C = a.FT || ',' || a.ST
where a.IOT = '0'
and a.CS = 'F'
and IOGD >= timestamp '2025-07-01 00:00:00'
and IOGD < timestamp '2025-07-03 00:00:00')
group by TNO, day) a
left join truck.B b on a.TNO = b.TNO;
到此时问题已经可以解决,我本想对比一下原始SQL与hint SQL的执行计划,并找出相关的函数索引,但是此时客户那边似乎忙着处理其他事情,无法继续提供远程方式,只得作罢。
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70047128/viewspace-3091980/ ,如需转载,请注明出处,否则将追究法律责任。