storage/db: add NOT NULL and PRIMARY KEY constraints to improve performance

In a test database containing 309,000 real benchmark records, given
the query

  select t1.UploadID, (select t2.Value from RecordLabels t2 where
  t2.UploadID = t1.UploadID AND Name = 'upload-time' limit 1) from
  Uploads t1;

used to obtain sample values from each upload, the PRIMARY KEY index
causes the query to fall from 1.49s to 0.03s.

The NOT NULL constraint is necessary to make the PRIMARY KEY effective.

Change-Id: I9e663766e2f99f1096952e4c20eecbf8faab577b
Reviewed-on: https://go-review.googlesource.com/36114
Reviewed-by: Russ Cox <rsc@golang.org>
1 file changed