Patches 1-4 and 6-9 are: Reviewed-by: Timothy Arceri <timothy.arceri at collabora.com> Patch 10 will give the correct result as discussed however I wouldn't mind seeing if I can come up with a patch that avoids the extra processing at query time. We really need to clean up these structures.