Alias our subqueries to appease the MySQL beast

This commit is contained in:
Jake Moshenko 2015-11-19 12:58:06 -05:00
parent 90ec66561d
commit 7ae94f414c

View file

@ -226,12 +226,14 @@ def lookup_repo_storages_by_content_checksum(repo, checksums):
# to use a union to select just one storage with each checksum # to use a union to select just one storage with each checksum
queries = [] queries = []
for checksum in set(checksums): for counter, checksum in enumerate(set(checksums)):
query_alias = 'q{0}'.format(counter)
candidate_subq = (ImageStorage candidate_subq = (ImageStorage
.select(ImageStorage.id, ImageStorage.content_checksum) .select(ImageStorage.id, ImageStorage.content_checksum)
.join(Image) .join(Image)
.where(Image.repository == repo, ImageStorage.content_checksum == checksum) .where(Image.repository == repo, ImageStorage.content_checksum == checksum)
.limit(1)) .limit(1)
.alias(query_alias))
queries.append(ImageStorage queries.append(ImageStorage
.select(SQL('*')) .select(SQL('*'))
.from_(candidate_subq)) .from_(candidate_subq))