Использую Postresql.
Есть таблица Documents с полями:
Account тип bigint Document тип bigint
User тип UUID
Есть 2 индекса
CREATE INDEX "AccountDocument" ON "Documents" USING btree ("Account" NULLS LAST, "Document" NULLS LAST)
WHERE ("Account" IS NOT NULL OR "Document" IS NOT NULL);
CREATE INDEX "AccountUserDocument" ON "Documents" USING btree ("Account", "User", "Document")
Для простого запроса хочу, чтобы использовался индекс AccountUserDocument
SELECT *
FROM "Documents"
WHERE "Account" = 1
AND "USER" = 'dd758b54-55b3-442a-804b-8a3d311432ba'::UUID
AND "Document" = 2
"Index Scan using "AccountDocument" on "Documents" (cost=0.29..8.31 rows=1 width=73) (actual time=0.016..0.016 rows=0 loops=1)"
" Index Cond: ("Document" = 2)"
" Filter: (("Account" = 1) AND ("USER" = 'dd758b54-55b3-442a-804b-8a3d311432ba'::uuid))"
" Buffers: shared hit=2"
"Planning time: 1.026 ms"
"Execution time: 0.039 ms"
"Index Scan using "AccoutUserDocument" on "Documents" (cost=0.28..8.30 rows=1 width=73) (actual time=3.626..3.626 rows=0 loops=1)"
" Index Cond: (("User" = 'dd758b54-55b3-442a-804b-8a3d311432ba'::uuid) AND ("Document" = 2))"
" Filter: ("Account" = 1)"
" Buffers: shared hit=73"
"Planning time: 0.946 ms"
"Execution time: 3.652 ms"
Вопрос почему индекс не используется с типом btree, только из-за того, что в индексе есть поле UUID?