Refactor query and add new indexes on various tables

Refactor latest_version_list query and new indexes on attributes, nodes, versions table respectively.