If I have a table with 4 columns(a,b,c,d)

I create the following index for this table :

ON table(a,b,c);

Will the PostgreSQL optimizer consider using the index in the following case:

WHERE a = v1 and b = v2 and c = v3 and d=f4;

Yes, PostgreSQL will definitely consider the index.

It may still choose not to use the index, for example if the table is too small or the condition is not selective enough.

You can temporarily

SET enable_seqscan = off;

to see if PostgreSQL can use the index or not. Just EXPLAIN the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.