'Creates an index with given fields if not already created.
Index name will be `fieldname1_fieldname2_index`'

def add_index(self, doctype, fields, index_name=None):

    if (not index_name):
        index_name = (u'_'.join(fields) + u'_index')
        index_name = re.sub(u'\\s*\\([^)]+\\)\\s*', u'', index_name)
    if (not frappe.db.sql((u'show    index    from    `tab%s`    where    Key_name="%s"    ' % (doctype, index_name)))):
        frappe.db.commit()
        frappe.db.sql((u'alter    table    `tab%s`\n DCTB  DCTB  DCTB  DCTB add    index    `%s`(%s)' % (doctype, index_name, u',    '.join(fields))))
