所以,我有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
你觉得这个,还是你测量过? –