What are your most common sql optimizations?

后端 未结 17 1625
谎友^
谎友^ 2020-12-12 14:51

What are your most common SQL optimization that you used?

17条回答
  •  旧时难觅i
    2020-12-12 14:58

    By far and above: Making covering indexes

    A covering index includes all the columns that the query will need, thereby avoiding the need to do lookups on the results of an index seek. This will then avoid the system feeling like a scan could be quicker (which is remarkably quick considering the cost of lookups).

    But also worth mentioning:

    Having an index that will allow a merge join. A MERGE join is able to occur when joining two tables that are ordered by the join conditions. But of course, in saying 'table', we really mean 'index', right...

    Also - removing scalar functions and using table-valued functions instead... as scalar functions are not able to be simplified out.

    Also - putting a unique index on a column that you know to be unique, allowing the query optimizer to use this knowledge to make better optimization choices. Also applies to NOT NULL constraints.

    Also - using Binary collation when comparing strings that are in a known case, so that the system doesn't have to consider the different case options.

    Of course I could go on all day...

    Rob

提交回复
热议问题