This is exactly what I was looking for! It worked pretty good for what I needed.
One improvement I would suggest is to find a way to deal with massive amounts of unused post meta. I had about 100,000 rows of unused post meta, and it wouldn't work. I deleted a bunch I knew for sure I didn't need, got it under 20,000 and it worked fine.