2

Is there any difference between the two following indexes in PostgreSQL:

CREATE INDEX my_index ON table_name (column_one, column_two)
   INCLUDE (account_id, id)

and

CREATE INDEX my_index ON table_name (column_one, column_two)
   INCLUDE (id, account_id)
Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
jjacobi
  • 385
  • 2
  • 9
  • 2
    The order of the columns in your index (column_one, column_two) is *CRITICAL*. The order of the columns in your (optional!) "INCLUDE" clause doesn't matter. For an excellent discussion of the hows/whys, look here: [A Close Look at the Index Include Clause](https://use-the-index-luke.com/blog/2019-04/include-columns-in-btree-indexes). – FoggyDay Jun 05 '20 at 20:10

1 Answers1

2

No, there is no difference in behavior between these two indexes. The order in the INCLUDE list does not matter.

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