0

Suppose I have table t1(c1, c2, c3, c4, c5,..)

I need to run queries where the columns (e.g. c1, c2, c3 here) used in where condition of select query as in below. The queries are making application slow.

  • select * from t1 where c1=somevalue1 and c2=somevalue2
  • select * from t1 where c3=somevalue1
  • select * from t1 where c1=somevalue1 and c2=somevalue2 and c3=somevalue

To improve performance of the queries, I want to create index on the columns which are used on where clause. what should be a better approach to create index on columns(c1, c2, c3)? multiple indexes like index1(c1), index2(c2), index3(c3), index4(c1, c2, c3) or Just one index like index1(c1, c2, c3)

Can anybody please advise on this??

Phoebe
  • 1
  • 1

1 Answers1

0

If the WHERE condition contains an arbitrary combinations of conditions on c1, c2 and c3, you are probably best off creating three single-column indexes on these three columns.

PostgreSQL can combine two index scans using a BitmapAnd if no single condition is selective enough, but the combination is.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263