所以,我有2個表:SQL訪問優化
items (id INTEGER PRIMARY KEY, imgurl text, defindex int, name text),
prices (id INTEGER PRIMARY KEY, defindex int, quality int, effect int, currency text, price real)
如果我需要仰視項目的名稱,價格和效果的名稱,我執行2個查詢:
SELECT currency, price from prices where defindex = :def and effect = :eff and quality = :qua
SELECT name, imgurl from items where defindex = :def
我想1個查詢替換它,但問題是,有時有項目,而不價格,所以defindex 202中存在的項目,而不是價格,所以
select prices.currency, prices.price, items.name, items.imgurl from items,prices where items.defindex = :def and prices.defindex = :def and prices.quality = :qua and prices.effect = :eff
將無法工作。 如何在不降低速度的情況下將其作爲一個查詢?
你爲什麼認爲兩個查詢會明顯慢?連接兩個表可能比兩個簡單的表查找花費更多的工作量。 –
我只是在優化我的網站,需要加載太多,我認爲數據庫請求需要時間從Python傳遞到實際的數據庫。 – RomaValcer
你覺得這個,還是你測量過? –