1
CREATE INDEX alias_pub_idx2
  ON info.palias
  USING btree
  (publisher_id, player_id, pub_player_id);

CREATE INDEX alias_pub_idx3
  ON info.palias
  USING btree
  (player_id);

The first includes the three columns; the latter includes only the one. I'm thinking they are redundant- that the first btree index is sufficient, but I'm not terribly familiar w/ the PostgreSQL indexing methods. Thoughts?

3
  • Is that valid? Last I heard, PostgreSQL didn't support covering indexes, which is what the alias_pub_idx2 is. Commented Aug 19, 2010 at 22:01
  • That's what I initially thought, OMG - but they're not covering indexes - info.palias must be schema.table syntax. Commented Aug 19, 2010 at 22:05
  • 1
    Yes, sorry, info.palias is schema.table.. Commented Aug 19, 2010 at 22:06

3 Answers 3

9

PostgreSQL multicolumn indexes are "ordered", which means this would be redundant only if player_id was the first column mentioned in alias_pub_idx2.

This, however, would be redundant :

CREATE INDEX alias_pub_idx2
  ON info.palias
  USING btree
  (publisher_id, player_id, pub_player_id);

CREATE INDEX alias_pub_idx3
  ON info.palias
  USING btree
  (publisher_id); /* first column of another index => waste of space */
Sign up to request clarification or add additional context in comments.

2 Comments

So it right to say that if player_id is the column more joined on (by far), it should either be the first column in the index, or have its own standalone index?
@Wells yes, that's right. From the documentation: " the index is most efficient when there are constraints on the leading (leftmost) columns"
0

Neither index makes the other redundant - a query against info.palias that looks for particular player_ids would favour the second index over the first if publisher_id is not also a criteria.

Comments

0

USING btree

BTREE indexes are ordered, that's why your second index is redundant: The first column is the same and can be used in all queries where player_id is a condition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.