Skip to main content

Order of the columns for composite primary key

  • January 5, 2018
  • 2 replies
  • 16 views

praveshbhardwaj
Forum|alt.badge.img+1

One of our customer wants to know if we have any recommendation on order of columns for PK. They want to know if the order of the columns is important and if yes what is the optimal order.
Vertica documentation doesn't discuss anything on this topic. However, we know that Vertica creates special key projections to enforce primary keys and the projections are sorted and segmented on the PK columns, in the same order as they are defined.

Considering this, does it mean that we should use the same guidelines for PK column order as for choosing projection sort order? e.g. put low cardinality column first, for same cardinality put column with smaller size first etc?

Anybody has any ideas/recommendation?

Thank you,
Pravesh

2 replies

marcothesane
Forum|alt.badge.img+1
  • Participating Frequently
  • January 5, 2018

Hi Pravesh -

I suppose you and I agree that a single-column primary key using a surrogate key would be preferrable in any case to several columns making up the primary key.

Having said that, I would indeed go go from low cardinality to higher cardinality in the ordinal position of the columns of a multi-column primary key.

You remember that PKs don't result in additional indexes, as that is sorted in the order columns of Vertica's projections, I suppose?

Cheers
Marco


praveshbhardwaj
Forum|alt.badge.img+1
  • Author
  • Participating Frequently
  • January 8, 2018

Hi Marco - Thanks for the inputs.
Cheers.