Descending order recommended for timestamp key / index?

Interesting because Cockroach is based so closely on Google Spanner. Does Cockroach Labs recommend to do this as well?

Noticed here: 架构设计最佳做法  |  Cloud Spanner  |  Google Cloud

Building out a fresh database and would like to know in advance if this makes sense in CRDB. Thanks!!

Hi Nathaniel!

The recommendation to " use descending order for timestamp-based keys" does not apply as much to CockroachDB, because 1) we don’t support interleaving (any more) and 2) we have a native ReverseScan KV operation that’s used for descending orders. However, ReverseScan has a small performance penalty, so the advice applies a little bit.

Reverse scans at the storage layer are about half the speed of forward scans. That is for large scans. For smaller scans the difference decreases. And there is other overhead beyond the storage layer that is constant for forward and reverse scans which also narrows the gap. If you are always accessing an index in descending order, it is better to store the data in reverse and use a forward scan, but this might not make a material difference in your query performance.

We would recommend experimenting to see whether it actually makes a difference for your application.

1 Like