1

Does the order of columns in the primary key impact the performance of related queries depending on the order of columns given in the select statement?

Example:

primary key (col1, col2, col3);

select col2, col3 from table;

-> would this select use the pk index?

select col3,col1,col2 from table;

-> would this select use the pk index?

Sebas
  • 21,192
  • 9
  • 55
  • 109

1 Answers1

2

No the order is not relevant. But the primary key index is only used if all primary key columns will be used inside a where clause (like all indices).

select ... from table where col1 = ... and col2 = ... and col3 = ...;

Sebastian Utz
  • 719
  • 3
  • 9
  • out of curiosity, where did you get that information from? The documentation is hardly ever helping me – Sebas Jul 17 '18 at 09:27