gpt4 book ai didi

sql - 在我的表中创建索引并没有降低我的成本

转载 作者:行者123 更新时间:2023-11-29 13:11:15 25 4
gpt4 key购买 nike

我有这张表:

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)
);

针对这个表,我执行以下查询:

select count(accident_index)as hits, first_road_class 
from accident_info
group by first_road_class;

没有索引。

我想创建一个索引来降低我的总成本,但到目前为止我创建的索引似乎不起作用。这是:

create index on accident_info(accident_index, first_road_class);

First ten Rows of my table

最佳答案

对于这个查询:

select count(accident_index) as hits, first_road_class 
from accident_info
group by first_road_class;

您可以在 accident_info(first_road_class, accident_index) 上尝试索引。列的顺序很重要。

关于sql - 在我的表中创建索引并没有降低我的成本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54408919/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com