Postgres即使创建索引也不会使用索引

时间:2019-01-28 21:44:41

标签: postgresql

我有下表:

Table Creation
accident_info
(
    accident_index varchar(20),
    first_road_class varchar(20),
    accident_severity varchar(20),
    date date,
    urban_or_rural_area varchar(20),
    weather_conditions varchar(40),
    year int,
    inscotland varchar(20)
);

索引:

CREATE INDEX index1 ON accident_info(accident_info.first_road_class , accident_info.date)

CREATE INDEX index2 ON accident_info(vehicle_info.age_band_of_driver)

查询:

SELECT COUNT(accident_info.accident_index) as max, vehicle_info.make
FROM vehicle_info
INNER JOIN accident_info on vehicle_info.accident_index = accident_info.accident_index
WHERE vehicle_info.age_band_of_driver = '26 - 35' AND accident_info.first_road_class = 'A' AND accident_info.date > '2009-12-31' and accident_info.date < '2013-01-01'
GROUP BY make
ORDER BY max DESC
LIMIT 1

即使我创建了两个索引,Postgres也不使用它们。为什么会这样?

1 个答案:

答案 0 :(得分:0)

也许您的数据集太小而无法使用索引