2011-11-01 128 views
1

在我们的项目中,我们有很大的no。数据(其属性列表网站),我将这些数据存储到Barkeley DB(XML DB)。问题是当我搜索一个房产时,它会很快列出前10个房产(100%的速度)。然后我要去2dn,第3页它以相同的速度工作。但是如果我要以10秒(30%速度)或100秒或1500秒(15%速度)的速度运行,速度非常缓慢。XQuery select查询无法正常工作

以下是我的查询:

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> 

而且有时查询将改变像基于在我的网页过滤选项下面的方式(仅SALE_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

回答

0

你不给查询规划足够的机会来优化你的查询。

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

如果您希望查询计划程序能够帮助您,我也会仔细考虑如何在执行子序列之前将其压缩到单个FLWOR而不是三个并置结果集。根据您的过滤需求,我没有理由认为这是不可能的。