This is the table:
dt VARCHAR(65)
ct VARCHAR(65)
amount INT
This is the query:
SELECT SUM(CASE WHEN dt='peter' THEN amount ELSE -amount END)
FROM receipt WHERE dt='peter' OR ct='peter'
I have 800k records in the table. And I have indexes on dt, ct, amount, and ct,dt. At the moment this query takes over 5 minutes (!).
explain analyze)