Aren't these backwards? Shouldn't the index be created with the same order as the columns? I am cherry-picking this into release-2.2, but I believe tmplvarid should be first in the index...