Combine AND(Fixed, SQL) into a single IN clause, reducing roundtrips. Add a test and benchmark.

This commit is contained in:
Barak Michener 2015-10-06 15:47:16 -04:00
parent 99283d5412
commit 277fc748e3
4 changed files with 74 additions and 11 deletions

View file

@ -224,9 +224,8 @@ func (l *SQLLinkIterator) buildWhere() (string, []string) {
q = append(q, fmt.Sprintf("%s.%s_hash = ?", l.tableName, c.dir))
vals = append(vals, hashOf(c.vals[0]))
} else if len(c.vals) > 1 {
subq := fmt.Sprintf("%s.%s_hash IN ", l.tableName, c.dir)
valslots := strings.Join(strings.Split(strings.Repeat("?", len(c.vals)), ""), ", ")
subq += fmt.Sprintf("(%s)", valslots)
subq := fmt.Sprintf("%s.%s_hash IN (%s)", l.tableName, c.dir, valslots)
q = append(q, subq)
for _, v := range c.vals {
vals = append(vals, hashOf(v))