Is there any general rule on SQL query complexity Vs performance?

后端 未结 4 1598
独厮守ぢ
独厮守ぢ 2020-12-07 18:10

1)Are SQL query execution times O(n) compared to the number of joins, if indexes are not used? If not, what kind of relationship are we likely to expect? And can indexing im

4条回答
  •  执念已碎
    2020-12-07 18:35

    Are SQL query execution times O(n) compared to the number of joins, if indexes are not used?

    Generally they're going to be O(n^m), where n is the number of records per table involved and m is the number of tables being joined.

    And can indexing improve the actual big-O time-complexity, or does it only reduce the entire query time by some constant factor?

    Both. Indexes allow for direct lookup when the joins are heavily filtered (i.e. with a good WHERE clause), and they allow for faster joins when they're on the right columns.

    Indexes are no help when they're not on the columns being joined or filtered by.

提交回复
热议问题