Add logic and tests for getAddIndexSql

Change-Id: If40e50513cb0794364421d0a31289e7c5baa74ba