2011-11-01 114 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而不是三個並置結果集。根據您的過濾需求,我沒有理由認爲這是不可能的。