XQuery选择查询无法正常工作

时间:2011-11-01 10:18:23

标签: php xquery

在我们的项目中我们有大号没有。数据(它是一个属性列表站点),我将这些数据存储到Barkeley DB(XML DB)。问题是,当我搜索属性时,它将快速列出前10个属性(100%速度)。然后我要去2dn,第3页它以相同的速度工作。但是,如果我要达到第10(30%速度)或第100或第1500(15%速度)页面工作非常缓慢。

以下是我的查询:

let $property_ids:= 
(
    for $property in collection('bdb/properties.dbxml')/properties/property
        [  ( sale_price >=60000 and sale_price <=500000 )  and  ( building_square_footage >=300 and building_square_footage <=3000 )  and  ( bedrooms >=2 and bedrooms <=6 )  and (mls_agent_id = '505199')  ] 
    order by $property/sale_price/number() descending
    return $property/@property_id,

    for $property in collection('bdb/properties.dbxml')/properties/property
        [  ( sale_price >=60000 and sale_price <=500000 )  and  ( building_square_footage >=300 and building_square_footage <=3000 )  and  ( bedrooms >=2 and bedrooms <=6 )  and (starts-with(mls_office_id, 'CBRR') and not(mls_agent_id = '505199'))  ]
    order by $property/sale_price/number() descending
    return $property/@property_id,

    for $property in collection('bdb/properties.dbxml')/properties/property
        [  ( sale_price >=60000 and sale_price <=500000 )  and  ( building_square_footage >=300 and building_square_footage <=3000 )  and  ( bedrooms >=2 and bedrooms <=6 )  and not(starts-with(mls_office_id, 'CBRR'))  ]
    order by $property/sale_price/number() descending
    return $property/@property_id
)
return <properties>{
    for $id in subsequence($property_ids, 1, 10) return 
        collection('bdb/properties.dbxml')/properties/property[@property_id = $id]
}</properties>

有时候查询会根据我页面中的过滤器选项改变,如下所示(意味着只按sales_price字段排序):

 let $property_ids:= 
    (
        for $property in collection('bdb/properties.dbxml')/properties/property
        order by $property/sale_price/number() descending
        return $property/@property_id
    )
    return <properties>{
        for $id in subsequence($property_ids, 1, 10) return 
            collection('bdb/properties.dbxml')/properties/property[@property_id = $id]
    }</properties>

然后从第一页开始,它的表现非常缓慢(15%)。

请您检查我的查询并帮我解决问题......

谢谢你, Vijesh

1 个答案:

答案 0 :(得分:0)

您没有给查询规划器足够的机会来优化您的查询。

不是加载一整套id然后使用它们的子序列来请求一些元素,而是尝试使用FLWOR表达式来检索元素并直接获得元素的子序列。

如果您希望查询计划程序帮助您,我还会考虑如何在执行子序列之前将其压缩为单个FLWOR而不是三个连接结果集。鉴于您的过滤需求,我认为没有理由不这样做。