对于以下场景,什么是最有效的索引? 3栏:
user_id, created_at, and name.
((user_id
和created_at
)一起查询,同时查询user_id
和name
。
created_at
和name
专门用于排序。举个例子:
SELECT "items".* FROM "items" WHERE "items"."user_id" = $1 ORDER BY created_at [["user_id", 1]]
或
SELECT "items".* FROM "items" WHERE "items"."user_id" = $1 ORDER BY name [["user_id", 1]]
我知道索引是从左到右的,所以"user_id, created_at"
和"user_id, name"
上的两个多列索引最好,或者有没有办法“共享”user_id索引(类似于3个索引) on user_id,created_at和name)?