Exists和In的一个代替方案

Posted by eDWARD at 16:55

项目需要,所以学习了一下如何想办法替代exists和in带来的性能问题,现给出一种方案:
首先定义两个TYPE,一个用来装INT,一个用来装VARCHAR

然后定义两个函数:

上面这两个函数分别接受用‘,’分隔的INT或VARCHAR串,然后填充到刚才建立的两个TYPE里,这样就可以联合查询而不用IN了。
最后在SQL里的使用方法如下,存错过程类似,所以就不举例了:)
select b.BidWordId, b.BidWord, b.MaxPrice, b.Title, b.Description, b.DisplayUrl, b.LinkUrl, b.Onlinestate, b.Validstate, c.Custstat, c.Custid from AuditList a, BidWord b, Customers c, (select COLUMN_VALUE from the (select cast(str2numList(?) as numTableType) from dual)) d where a.BidWordID = b.BidWordID and b.CustID = c.CustID and a.AuditState = 40 and a.CompleteType = 10 and a.TicketID = d.COLUMN_VALUE order by a.CompleteTime desc

Sphere: Related Content

Filed In 学习路上 | Study | Tags: |

Your Comments.

Leave your own response

Leave a Reply.

Comment Form.

Fields denoted with a "*" are required. Your comment may require moderation, please be patient.

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>




Your Reply.

Use the following link to trackback from your own site:
http://www.zhangzhang.net/articles/2006/09/21/exists-and-in-replaces-the-plan/trackback/

Spread the word.

Octopus supports RSS feed for this post RSS 2.0 , and Trackbacks from other blogs.

Technorati

  品位不凡,威严,略显高深,喜爱一切美丽的事物,易怒,固执,有些利己,但关心接近他的人。谦逊,但非常有野心,有才能,刻苦,是不甚令人满意的伴侣,朋友众多,树敌也多,是可以信赖的人。


bloglines
google reader
my yahoo
订阅我的博客