private void updateKeyConstraintsInBatch(Map<Long, Long> oldCdIdToNewCdId,
                                           Map<Long, List<Pair<Integer, Integer>>> oldCdIdToColIdxPairs) throws MetaException {
    List<Long> oldCdIds = new ArrayList<>(oldCdIdToNewCdId.keySet());
    String tableName = "\"KEY_CONSTRAINTS\"";
    List<String> parentColumns = Arrays.asList("\"PARENT_CD_ID\"", "\"PARENT_INTEGER_IDX\"");
    List<String> childColumns = Arrays.asList("\"CHILD_CD_ID\"", "\"CHILD_INTEGER_IDX\"");

    String updateParent = TxnUtils.createUpdatePreparedStmt(tableName, parentColumns, parentColumns);
    String updateChild = TxnUtils.createUpdatePreparedStmt(tableName, childColumns, childColumns);
    for (String updateStmt : new String[]{updateParent, updateChild}) {
      int maxRows = dbType.getMaxRows(maxBatchSize, 4);
      updateWithStatement(statement -> Batchable.runBatched(maxRows, oldCdIds,
          new Batchable<Long, Void>() {
            @Override
            public List<Void> run(List<Long> input) throws SQLException {
              for (Long oldId : input) {
                // Followed the jdo implement to update only mapping columns for KEY_CONSTRAINTS.
                if (!oldCdIdToColIdxPairs.containsKey(oldId)) {
                  continue;
                }
                Long newId = oldCdIdToNewCdId.get(oldId);
                for (Pair<Integer, Integer> idx : oldCdIdToColIdxPairs.get(oldId)) {
                  statement.setLong(1, newId);
                  statement.setInt(2, idx.getRight());
                  statement.setLong(3, oldId);
                  statement.setInt(4, idx.getLeft());
                  statement.addBatch();
                }
              }
              statement.executeBatch();
              return null;
            }
      }), updateStmt);
    }
  }
Gets the next CS id from sequence MPartitionColumnStatistics and increment the CS id by numStats.
@return The CD id before update.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/DirectSqlUpdatePart.java