SQL indexing on varchar

前端 未结 5 840
伪装坚强ぢ
伪装坚强ぢ 2020-12-25 15:32

I have a table whose columns are varchar(50) and a float. I need to (very quickly) look get the float associated with a given string. Even with ind

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-25 15:44

    By declaring an index on (phrase, assoc, floatval) you will get a "covering index", which allows the query posted in the question to performed without even accessing the table. Assuming that either phrase or assoc alone is highly selective (not many rows share the same value for the field), creating an index on that field alone should yield almost the same performance.

    Generally, you will want to limit the number of indexes to the smallest set that gets your frequent queries up to the desired performance. For each index you add to a table, you pay some disk space, but more importantly you pay the price of having the DBMS do more work on each INSERT into the table.

提交回复
热议问题