Subject Slower fetchall after creating indices
Author jasperelzinga
Hello,

Im having a strange problem after i create indices.

Normal situation:
>>> timeExecute("SELECT Instantie.id FROM Instantie WHERE
Instantie.deleted=0 ORDER BY Instantie.telefoon ASC", [])
execute time: 0.56299996376
>>> a = timeFetchall()
fetchall time: 0.140999794006

This selects 10.000 records, sorted on column 'telefoon' which has no
index.

Create an index on telefoon:
>>> cur.execute("CREATE INDEX temp ON Instantie (telefoon)")
>>> con.commit()
>>>

And now i execute the exact same query:
>>> timeExecute("SELECT Instantie.id FROM Instantie WHERE
Instantie.deleted=0 ORDER BY Instantie.telefoon ASC", [])
execute time: 0.0
>>> b = timeFetchall()
fetchall time: 0.65700006485

The execute time has been reduced a lot, that is what i'd expected.
But.. the fetchall time is now more than half a second!

Ok.. and to be sure, check if the results are te same:
>>> a == b
True

Im really puzzeled by this situation. The fetchall method just returns
the data (a list of tuples), which is exactly the same in both
situations. I can't think of any reason why it could slow down. There
are 10.000 records in the table and it has 55 columns, with 'id' as
primary key with an index on it.

What could be the reason and what could i do to fix this problem?

Thanks in advance,

Jasper Elzinga