SQL query to select million records quickly

后端 未结 4 1089
[愿得一人]
[愿得一人] 2021-02-04 22:03

I want to select million records from a table and I am using select query for this.

Currently it is taking a few minutes to get data. Can I get it quickly?<

4条回答
  •  忘掉有多难
    2021-02-04 22:36

    There's a few factors that would go into this. A quick list of things to look at:

    1. The speed of your server. CPU, memory, network connection would all be factors
    2. If you are doing a SELECT statement with conditions (ie. using a WHERE) or one with JOINS, having indexes will improve your performance, especially on a table with millions of rows. Hash tables will do a huge net positive on a large table.
    3. Writing clean queries. For example, if you have a large list of items you need to exclude from a query, perform a LEFT JOIN instead of using a NOT IN condition.

    This is really just the tip of the iceberg, but some of the easiest things to implement will also provide you with some of the biggest performance boosts.

提交回复
热议问题