# UNDF: UNDF-2026-000000395
# flink-0002: RowTypeUtils.getUniqueName — List.contains() inside nested for+do-while

## Defect ID
flink-0002

## File:Line
`flink-table/flink-table-common/src/main/java/org/apache/flink/table/typeutils/RowTypeUtils.java:43,49`

## Description
`getUniqueName(List<String> oldNames, List<String> checklist)` does:

```java
for (String oldName : oldNames) {                         // O(N)
    if (checklist.contains(oldName) || result.contains(oldName)) {  // O(M) + O(R)
        do {
            changedName = oldName + "_" + suffix++;
        } while (checklist.contains(changedName) || result.contains(changedName)); // O(M) + O(R) per iteration
        result.add(changedName);
    } else {
        result.add(oldName);
    }
}
```

Both `checklist` and `result` are `List<String>`. Each `.contains()` is O(M) or O(R).
The do-while iterates up to K times per name (until a unique suffix is found).
Total complexity: O(N × (M + R) × K) which approaches O(N × M²) in the worst case
when many names clash and checklist is large.

This method is called during SQL query planning whenever column names must be
deduplicated (e.g., join projections, window aggregations) — it runs on every query.

## Complexity
- Slow: O(N × M × K) — List.contains() = O(M)
- Fast: O(N × K) — HashSet.contains() = O(1)

## Severity
MEDIUM

## Speedup Estimate
~M× improvement; at M=100 column names per relation, ~100x.

## Fix
Convert `checklist` to `HashSet<String>` at call sites, or convert internally at
method entry. Build a `HashSet<String> seen` from `checklist` plus accumulate
`result` into a parallel `HashSet<String>` for O(1) membership checks.
