(FR #894) Crazy sql to rebuild corrupt logs

Change-Id: I51146a7392a05ca6227c3dae1afdb869ce7e80e4
Merge "(FR #894) Crazy sql to rebuild corrupt logs"