You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
创建个新表create table a(id int,t_date timestamp,name varchar);
添加索引create index idx_date on a using btree(t_date desc);
create index idx_date_name on a using btree(t_date desc,name);
查询语句如:select * from a where t_date >='time1' and t_date <'time2' and name in ('a','b','c') order by t_date desc limit 10;
这样的查询执行计划会走单时间索引,选择出时间范围的数据在过滤name 数组,而不会像Oracle一样直接走date和name的联合索引直接查询?
希望得到德哥的解释,谢谢。
The text was updated successfully, but these errors were encountered:
这个查询取决于a,b,c的过滤性, 如果过滤性好, 可能就直接使用name的单一索引.
如果过滤性不好, 可以使用partial index: create index on a (t_date desc) where (name in ('a','b','c'));
但是使用idx_date_name还不如使用including语法, 把name放到idx_date的叶子结点中.
创建个新表create table a(id int,t_date timestamp,name varchar);
添加索引create index idx_date on a using btree(t_date desc);
create index idx_date_name on a using btree(t_date desc,name);
查询语句如:select * from a where t_date >='time1' and t_date <'time2' and name in ('a','b','c') order by t_date desc limit 10;
这样的查询执行计划会走单时间索引,选择出时间范围的数据在过滤name 数组,而不会像Oracle一样直接走date和name的联合索引直接查询?
希望得到德哥的解释,谢谢。
The text was updated successfully, but these errors were encountered: