I have the following two pieces of code:
First, in SQL:
self.cursor.execute('SELECT apple_id FROM main_catalog WHERE apple_id=%s', apple_id)
if self.cursor.fetchone():
print '##'
Next, in Django:
if Catalog.objects.filter(apple_id=apple_id).exists():
print '>>>'
Doing it the first way is about 4x faster than the second way in a loop of 100k entries. What accounts for Django being so much slower?