refactor creation of mmTables. add indexes in sql