private void updateAdminPrivilegeRecords() throws SQLException {
    final String temporaryTable = ADMINPRIVILEGE_TABLE + "_tmp";

    // Make sure the temporary table does not exist
    dbAccessor.dropTable(temporaryTable);

    // Create temporary table
    List<DBAccessor.DBColumnInfo> columns = new ArrayList<>();
    columns.add(new DBAccessor.DBColumnInfo(ADMINPRIVILEGE_PRIVILEGE_ID_COLUMN, Long.class, null, null, false));
    columns.add(new DBAccessor.DBColumnInfo(ADMINPRIVILEGE_PERMISSION_ID_COLUMN, Long.class, null, null, false));
    columns.add(new DBAccessor.DBColumnInfo(ADMINPRIVILEGE_RESOURCE_ID_COLUMN, Long.class, null, null, false));
    columns.add(new DBAccessor.DBColumnInfo(ADMINPRIVILEGE_PRINCIPAL_ID_COLUMN, Long.class, null, null, false));
    dbAccessor.createTable(temporaryTable, columns);

    // Insert updated data
    /* *******
     * Find the principal id for the merged user records for the user that is related to each relevant
     * adminprivilege record.
     * - Using the principal_id from the original adminprivilege record, find the user_name of that user.
     * - Using the found user_name, find the user_id for the _merged_ record.  This will be the value of the
     *   smallest user_id for all user_ids where the user_name matches that found user_name.
     * - Using the found user_id, obtain the relevant principal_id
     * - The user_name value is case-insensitive.
     * ******* */
    dbAccessor.executeUpdate(
      "insert into " + temporaryTable + " (" + ADMINPRIVILEGE_PRIVILEGE_ID_COLUMN + ", " + ADMINPRIVILEGE_PERMISSION_ID_COLUMN + ", " + ADMINPRIVILEGE_RESOURCE_ID_COLUMN + ", " + ADMINPRIVILEGE_PRINCIPAL_ID_COLUMN + ")" +
        "  select" +
        "    ap." + ADMINPRIVILEGE_PRIVILEGE_ID_COLUMN + "," +
        "    ap." + ADMINPRIVILEGE_PERMISSION_ID_COLUMN + "," +
        "    ap." + ADMINPRIVILEGE_RESOURCE_ID_COLUMN + "," +
        "    ap." + ADMINPRIVILEGE_PRINCIPAL_ID_COLUMN +
        "  from " + ADMINPRIVILEGE_TABLE + " ap" +
        "  where ap." + ADMINPRIVILEGE_PRINCIPAL_ID_COLUMN + " not in" +
        "        (" +
        "          select " + USERS_PRINCIPAL_ID_COLUMN +
        "          from " + USERS_TABLE +
        "        )" +
        "  union" +
        "  select" +
        "    ap." + ADMINPRIVILEGE_PRIVILEGE_ID_COLUMN + "," +
        "    ap." + ADMINPRIVILEGE_PERMISSION_ID_COLUMN + "," +
        "    ap." + ADMINPRIVILEGE_RESOURCE_ID_COLUMN + "," +
        "    t.new_principal_id" +
        "  from " + ADMINPRIVILEGE_TABLE + " ap inner join" +
        "    (" +
        "      select" +
        "        u." + USERS_USER_ID_COLUMN + "," +
        "        u." + USERS_USER_NAME_COLUMN + "," +
        "        u." + USERS_PRINCIPAL_ID_COLUMN + " as new_principal_id," +
        "        t1." + USERS_PRINCIPAL_ID_COLUMN + " as orig_principal_id" +
        "      from " + USERS_TABLE + " u inner join" +
        "        (" +
        "          select" +
        "            u1." + USERS_USER_NAME_COLUMN + "," +
        "            u1." + USERS_PRINCIPAL_ID_COLUMN + "," +
        "            t2.min_user_id" +
        "          from " + USERS_TABLE + " u1 inner join" +
        "            (" +
        "              select" +
        "                lower(" + USERS_USER_NAME_COLUMN + ") as " + USERS_USER_NAME_COLUMN + "," +
        "                min(" + USERS_USER_ID_COLUMN + ") as min_user_id" +
        "              from " + USERS_TABLE +
        "              group by lower(" + USERS_USER_NAME_COLUMN + ")" +
        "            ) t2 on (lower(u1." + USERS_USER_NAME_COLUMN + ") = lower(t2." + USERS_USER_NAME_COLUMN + "))" +
        "        ) t1 on (u." + USERS_USER_ID_COLUMN + " = t1.min_user_id)" +
        "    ) t on (ap." + ADMINPRIVILEGE_PRINCIPAL_ID_COLUMN + " = t.orig_principal_id)");

    // Truncate existing adminprivilege records
    dbAccessor.truncateTable(ADMINPRIVILEGE_TABLE);

    // Insert temporary records into adminprivilege table
    /*
     * Copy the generated data to the original <code>adminprivilege</code> table, effectively skipping
     * duplicate records.
     */
    dbAccessor.executeUpdate(
      "insert into " + ADMINPRIVILEGE_TABLE + " (" + ADMINPRIVILEGE_PRIVILEGE_ID_COLUMN + ", " + ADMINPRIVILEGE_PERMISSION_ID_COLUMN + ", " + ADMINPRIVILEGE_RESOURCE_ID_COLUMN + ", " + ADMINPRIVILEGE_PRINCIPAL_ID_COLUMN + ")" +
        "  select " +
        "    min(" + ADMINPRIVILEGE_PRIVILEGE_ID_COLUMN + ")," +
        "    " + ADMINPRIVILEGE_PERMISSION_ID_COLUMN + "," +
        "    " + ADMINPRIVILEGE_RESOURCE_ID_COLUMN + "," +
        "    " + ADMINPRIVILEGE_PRINCIPAL_ID_COLUMN +
        "  from " + temporaryTable +
        "  group by " + ADMINPRIVILEGE_PERMISSION_ID_COLUMN + ", " + ADMINPRIVILEGE_RESOURCE_ID_COLUMN + ", " + ADMINPRIVILEGE_PRINCIPAL_ID_COLUMN);

    // Delete the temporary table
    dbAccessor.dropTable(temporaryTable);
  }
Update the <code>adminprivilege</code> table to ensure records for the same username but different user
records are referencing the main user record. Duplicate records will be be ignored when updating
the <code>adminprivilege</code> table.
<p>
If <code>UserA:LOCAL</code>, <code>usera:LOCAL</code> and <code>usera:LDAP</code> are assigned
to <code>Role1</code>, the three <code>adminprivilege</code> records will be merged into a single
record for <code>usera</code>.
<p>
This method may be executed multiple times and will yield the same results each time.

@throws SQLException if an error occurs while executing SQL statements
ambari-server/src/main/java/org/apache/ambari/server/upgrade/UpgradeCatalog270.java