DECLARE
    i INTEGER;
    j INTEGER;
    k INTEGER;
BEGIN
    SELECT COUNT(*) INTO i FROM user_indexes WHERE index_name = 'IDX_USER_ROLE_USER_TENANT';
    SELECT COUNT(*) INTO j FROM user_indexes WHERE index_name = 'IDX_USER_ROLE_ROLE_TENANT';
    SELECT COUNT(*) INTO k FROM user_indexes WHERE index_name = 'IDX_USER_ATTRIBUTE_USER_TENANT';
    IF i = 0 THEN
        EXECUTE IMMEDIATE 'CREATE INDEX IDX_USER_ROLE_USER_TENANT ON UM_USER_ROLE(UM_USER_ID,UM_TENANT_ID)';
    END IF;
    IF j = 0 THEN
        EXECUTE IMMEDIATE 'CREATE INDEX IDX_USER_ROLE_ROLE_TENANT ON UM_USER_ROLE(UM_ROLE_ID,UM_TENANT_ID)';
    END IF;
    IF k = 0 THEN
        EXECUTE IMMEDIATE 'CREATE INDEX IDX_USER_ATTRIBUTE_USER_TENANT ON UM_USER_ATTRIBUTE(UM_USER_ID,UM_TENANT_ID)';
    END IF;
END;
/
