新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> Oracle, SQL Server与XML,XML在数据挖掘中的应用, PMML.
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - 高级XML应用『 XML 与 数据库 』 → [讨论]let子句在SQLServer2005中的等效问题 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 5927 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [讨论]let子句在SQLServer2005中的等效问题 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     蒙面的羔羊 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:58
      门派:XML.ORG.CN
      注册:2007/5/22

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给蒙面的羔羊发送一个短消息 把蒙面的羔羊加入好友 查看蒙面的羔羊的个人资料 搜索蒙面的羔羊在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看蒙面的羔羊的博客楼主
    发贴心情 [讨论]let子句在SQLServer2005中的等效问题

    hi :)

    因为SS2005不支持let子句, 在改写有let语句的查询时遇到一些问题,想看看大家有什么好的解决.

    我查了msdn, 这个帖子能解决一些问题:
    If the LET expression does not contain any construction, then replace all occurrences of the LET variable with that expression. This workaround will evaluate the expression each time and have some performance impact. If the expression yields a scalar value, you can use sql:variable() to compute it once outside the XQuery and use it in XQuery. A similar use is shown in http://blogs.msdn.com/spal/archive/2005/04/06/405943.aspx.

    If the LET expression contains a construction, then you need to break up the query and do it partly in Transact-SQL and partly using XQuery. If you send me your query, I (or someone from our team) can help with the rewrite.


    但对于下面这个改写,一直找不到好的方法:
    原查询:
    for $p in /site/people/person
    let $l := for $i in /site/open_auctions/open_auction/initial
    where $p/profile/@income > (5000 * $i/text())
    return $i
    return <items name=$p/profile/@income> count ($l) </items>

    改写后的查询:
    for $p in /site/people/person,
    $i in /site/open_auctions/open_auction/initial
    where ($p/profile/@income)[1] ge (5000 * ($i/text())[1])
    return <items name="{$p/profile/@income}">{count(/site/open_auctions/open_auction/initial[text()[1] le ($p/profile/@income)[1]])}</items>

    原查询中用let定义了一个序列$l ,其中包含在值连接
    where $p/profile/@income > (5000 * $i/text())
    return $i
    中得到的$i节点集合,对每个$p只需要做1次这种值连接,连接得到的集合可以保存起来,供后续查询使用。

    改写后,因为无法使用let赋值,只有在count中再次使用连接,而不能直接使用刚才得到的结果
    (/site/open_auctions/open_auction/initial[ text()[1] le ($p/profile/@income)[1]] )

    而这类连接是非常消耗时间的,我在10M的数据上测试,上面的查询花费了19分钟,

    现在的问题是,有什么办法可以避免这种重复计算,谢谢 :)


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/5/22 10:21:00
     
     蒙面的羔羊 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:58
      门派:XML.ORG.CN
      注册:2007/5/22

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给蒙面的羔羊发送一个短消息 把蒙面的羔羊加入好友 查看蒙面的羔羊的个人资料 搜索蒙面的羔羊在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看蒙面的羔羊的博客2
    发贴心情 
    另一个关于重构的问题:

    原查询:
    Q10:根据其兴趣分组列出所有的人员,标签使用法语.
    FOR $i IN DISTINCT
    /site/people/person/profile/interest/@category
    LET $p := FOR $t IN /site/people/person
    WHERE $t/profile/interest/@category = $i
    RETURN <personne>
    <statistiques>
    <sexe> $t/gender/text() </sexe>,
    <age> $t/age/text() </age>,
    <education> $t/education/text()</education>,
    <revenu> $t/income/text() </revenu>
    </statistiques>,
    <coordonnees>
    <nom> $t/name/text() </nom>,
    <rue> $t/street/text() </rue>,
    <ville> $t/city/text() </ville>,
    <pays> $t/country/text() </pays>,
    <reseau>
    <courrier> $t/email/text() </courrier>,
    <pagePerso> $t/homepage/text()</pagePerso>
    </reseau>,
    </coordonnees>
    <cartePaiement> $t/creditcard/text()</cartePaiement>
    </personne>

    RETURN
    <categorie>
    <id> $i </id>,
    $p
    </categorie>

    注意,这里把序列$p放在最后返回的结果<categorie>中了,如果改写成

    '
    for $i in distinct-values(/site/people/person/profile/interest/@category),
    $t in /site/people/person
    return
    <categorie><id>{$i}</id> <personne> <statistiques> <sexe>{$t/gender/text()}</sexe>, <age>{$t/age/text()}</age>, <education>{$t/education/text()}</education>, <revenu>{$t/income/text()}</revenu> </statistiques>, <coordonnees> <nom>{$t/name/text()}</nom>, <rue>{$t/street/text()}</rue>, <ville>{$t/city/text()}</ville>, <pays>{$t/country/text()}</pays>, <reseau> <courrier>{$t/email/text()}</courrier>, <pageperso>{$t/homepage/text()}</pageperso> </reseau>, </coordonnees> <cartepaiement>{$t/creditcard/text()}</cartepaiement> </personne> </categorie> '

    则查询得到的结果类似下面的情况:

    categorie>
      <id>category38</id>
      <personne>
        <statistiques>
          <sexe />, <age />, <education />, <revenu /></statistiques>, <coordonnees><nom>Torkel Prodrodmidis</nom>, <rue />, <ville />, <pays />, <reseau><courrier />, <pageperso /></reseau>, </coordonnees><cartepaiement>5144 2585 6148 3007</cartepaiement></personne>
    </categorie>
    <categorie>
      <id>category38</id>
      <personne>
        <statistiques>
          <sexe />, <age />, <education />, <revenu /></statistiques>, <coordonnees><nom>Gul Prodrodmidis</nom>, <rue />, <ville />, <pays />, <reseau><courrier />, <pageperso /></reseau>, </coordonnees><cartepaiement /></personne>
    </categorie>
    <categorie>
      <id>category38</id>
      <personne>
        <statistiques>
          <sexe />, <age />, <education />, <revenu /></statistiques>, <coordonnees><nom>Theron Aseltine</nom>, <rue />, <ville />, <pays />, <reseau><courrier />, <pageperso /></reseau>, </coordonnees><cartepaiement>6099 6159 7416 8032</cartepaiement></personne>
    </categorie>
    <categorie>
      <id>category38</id>
      <personne>
        <statistiques>
          <sexe />, <age />, <education />, <revenu /></statistiques>, <coordonnees><nom>Guillermo Litecky</nom>, <rue />, <ville />, <pays />, <reseau><courrier />, <pageperso>http://www.stanford.edu/~Litecky</pageperso></reseau>, </coordonnees><cartepaiement>1437 9349 4810 4089</cartepaiement></personne>
    </categorie>

    这也和原查询的意图不同

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/5/22 11:42:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XML 与 数据库 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/5/3 3:39:49

    本主题贴数2,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.500ms