我正在使用Rails和Postgres。使用STI時索引在哪裏?
我有幾個使用STI的模型,我想知道我應該在表上放置索引,爲什麼?
例如可以說我有以下設置:
class Comment < AR; end
class MovieComment < Comment; end
class MagazineComment < Comment; end
# Fake Comment Table
id:integer
title:string
body:text
type:string
謝謝!
你介意更詳細地說明爲什麼不值得索引'type'列嗎? – shinnyx 2017-01-03 04:13:14
索引有助於從數據庫中選擇單個記錄(或一小組記錄)。當你的選擇標準包含大部分表格時(假設20%的評論是「MovieComment」,80%是「MagazineComment」),數據庫可能會決定每次進行全表掃描會更便宜。 http://stackoverflow.com/questions/33911589/mysql-does-not-always-use-index – Daniel 2017-02-15 01:17:38