storage/db: query optimizations for duplicate keys

Queries with multiple parts referring to the same key are now
simplified before sending to the database. If the query can be proven
to return no results, the query is not sent to the database at all.

Change-Id: I2d307d09f463fb0e6e7bd9b9902115916e7ffffa
Reviewed-on: https://go-review.googlesource.com/36953
Run-TryBot: Quentin Smith <quentin@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
4 files changed