今天写一个存储过程,由于执行的时间比较长(7秒)所以打算优化一下.结果在优化测试代码中发现如下一个奇怪的现象.
现在有一个表mis_gl_balance,其中有一个字段ACC_SEGMENT VARCHAR(181) NULL,他的内容的形式如下:
3810.105301.5414070180.000000.00000000.0000.000000
另外一个表finance_budget_account 主要记录了budget_type 预算类型和mis_code MIS系统编码.这里的MIS编码就是ACC_SEGMENT表中的第三段.
为了查询出某种预算类型的所有ACC_SEGMENT,所以写了如下这样的代码:<div style="border-right: #cccccc 1px solid; padding-right: 5px; border-top: #cccccc 1px solid; padding-left: 4px; font-size: 13px; padding-bottom: 4px; border-left: #cccccc 1px solid; width: 98%; word-break: break-all; padding-top: 4px; border-bottom: #cccccc 1px solid; background-color: #eeeeee">
<img src="/Images/OutliningIndicators/None.gif" align="top" alt=""><span style="color: #0000ff">select<span style="color: #000000">?ACC_SEGMENT<img src="/Images/OutliningIndicators/None.gif" align="top" alt=""><span style="color: #0000ff">from<span style="color: #000000">?dbo.mis_gl_balance<img src="/Images/OutliningIndicators/None.gif" align="top" alt=""><span style="color: #0000ff">where<span style="color: #000000">?<span style="color: #ff00ff">LEFT<span style="color: #000000">(ACC_SEGMENT,<span style="font-weight: bold; color: #800000">22<span style="color: #000000">)?<span style="color: #808080">IN<span style="color: #000000">?(<span style="color: #0000ff">SELECT<span style="color: #000000">?<span style="color: #ff0000">'<span style="color: #ff0000">3810.105301.<span style="color: #ff0000">'<span style="color: #808080">+<span style="color: #000000">mis_code<img src="/Images/OutliningIndicators/None.gif" align="top" alt=""><span style="color: #0000ff">FROM<span style="color: #000000">?????????finance_budget_account<img src="/Images/OutliningIndicators/None.gif" align="top" alt=""><span style="color: #0000ff">WHERE<span style="color: #000000">?????budget_type?<span style="color: #808080">=<span style="color: #000000">?<span style="color: #ff0000">'<span style="color: #ff0000">电路租费<span style="color: #ff0000">'<span style="color: #000000">)
以上SQL语句就是把某种电路租费的ACC_SEGMENT全部取出来了.执行效率还能够接收,1秒钟就完成了.
但是如果改成了如下的代码:
比较这两段SQL.我们只是将其中的一个字符串'3810'写成了参数的形式,但是执行的效率就完全不一样了.
第二种SQL语句花费了7秒钟的时间.
为什么同样的SQL语句,执行效率相差那么大拉? (编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|