Results within radius - Optimising slow MySQL query

后端 未结 2 1416
温柔的废话
温柔的废话 2020-12-22 09:38
SELECT property.paon, property.saon, property.street, property.postcode, property.lastSalePrice, property.lastTransferDate,
 epc.ADDRESS1, epc.POSTCODE, epc.TOTAL_FL         


        
相关标签:
2条回答
  • 2020-12-22 10:02

    Do you control the database? If you do, you could try adding indexes on the address and postcode columns (anything in the join clause). That should probably speed up the query.

    Edit: reread your question.

    If the GROUP BY and ORDER BY clauses are slowing it down, I would try adding indexes on the columns referenced in those clauses.

    0 讨论(0)
  • 2020-12-22 10:10

    You can do a few things:

    • Create a new column so you don't need to use CONCAT CONCAT(property.paon, ', ', property.street) in the GROUP BY and the JOIN (this will speed it up a lot!)
    • As JackHacks says you need to create indexes at the right spot. (property postcode and the newly created column, and epc postcode and address)
    • Remove the HAVING with epc.TOTAL_FLOOR_AREA > 0 and add it to the WHERE

    If you need more help, share en EXPLAIN of your query with us.

    0 讨论(0)
提交回复
热议问题