Is there another way? The performance is unacceptable for a small test table < 500 records. (I let it run for 20 minutes before killing it).

I can't imagine this on a real table with > 1 million records.