Database 索引问题:选择*with WHERE子句。在何处以及如何创建索引
我正在优化我的一些查询,我有一个查询说明: 从SC中选择*其中c_id=“+c_id” **SC**的架构如下所示:Database 索引问题:选择*with WHERE子句。在何处以及如何创建索引,database,db2,indexing,query-optimization,Database,Db2,Indexing,Query Optimization,我正在优化我的一些查询,我有一个查询说明: 从SC中选择*其中c_id=“+c_id” **SC**的架构如下所示: SC ( c_id int not null, date_start date not null, date_stop date not null, r_t_id int not null, nt int, t_p decimal, PRIMARY KEY (c_id, r_t_id, date_start, date_stop)); 我对如何创建索引的直接出价是一
SC ( c_id int not null, date_start date not null, date_stop date not null, r_t_id int not null, nt int, t_p decimal, PRIMARY KEY (c_id, r_t_id, date_start, date_stop));
我对如何创建索引的直接出价是一个覆盖索引,顺序如下:
INDEX(c_id, date_start, date_stop, nt, r_t_id, t_p)
我下此订单的原因基于:
WHERE子句从c_id中进行选择,从而使其成为第一个排序顺序。
接下来,使用date\u start和date\u stop来指定要在这些参数中定义的某种“范围”
接下来是nt,因为它将选择nt
接下来是r\u t\u id,因为它是我的r\u t表的特定类型的id
最后是t_p,因为它只是一个信息
我不知道当它是SELECT all语句时,是否有必要以特定的方式对其进行排序。
我应该说,SC不是最大的表。我可以说它包含多少行,但估计值可能在之间,因为你说的是最多1000行,不要太在意索引,除非你在生产中遇到问题。我从来没有见过1000行表是一个问题。顺便说一句,你可以将C_ID作为主键。因此不需要额外的索引,因为表已经使用主键排序