subquery or leftjoin with group by which one is faster?

前端 未结 3 2092
忘掉有多难
忘掉有多难 2020-11-28 14:52

\"Queryi have to show running total with the total column in my application ... so i have used the fol

3条回答
  •  我在风中等你
    2020-11-28 15:19

    Your question wasn't very precise, so here are a few general rules that should be answer it.

    • Add an index. On your oversimplified sample, it would be on col1.
    • Use EXPLAIN to compare the queries. This will give you hints on what will happen with larger data.
    • Test on (real) data and optimize your server. The query time will depend on many parameters. For instance, does your data fit in the server's memory? Or are your buffers configured large enough?
    • Uses caches to divert queries from the DB server. Memcached is the most used in-memory application-level cache, but other caches exist at every level.

提交回复
热议问题