java-topology/defects/tidb/patch/tidb-0003-list-partition-group-intersect-linear-scan.patch
russell@unturf.com 76ffba4a60 tidb/scylladb: CWE-407 scan — renumber tidb patches, stamp UNDF
tidb-0001: partition drop name lookup O(P×D) → O(P+D) (27x at P=8192)
tidb-0002: predicate simplification (merged into tidb-0002 in prior commit)
tidb-0003: list partition group intersect O(G²) → O(G) (renumbered from 0002)
scylladb-0001: UNDF stamp added
2026-03-30 10:13:33 -04:00

25 lines
835 B
Diff

# UNDF: UNDF-2026-000000767
# UNDF: (leave blank)
--- a/pkg/table/tables/partition.go
+++ b/pkg/table/tables/partition.go
@@ -640,13 +640,17 @@ func (pg *ListPartitionGroup) intersect(otherPg ListPartitionGroup) bool {
if pg.PartIdx != otherPg.PartIdx {
return false
}
+ // CWE-407 fix: build a hash set from pg.GroupIdxs once (O(G)) so that
+ // the membership check inside the loop is O(1) instead of O(G).
+ // Old complexity: O(G²); new complexity: O(G).
+ existing := make(map[int]struct{}, len(pg.GroupIdxs))
+ for _, gidx := range pg.GroupIdxs {
+ existing[gidx] = struct{}{}
+ }
var groupIdxs []int
for _, gidx := range otherPg.GroupIdxs {
- if pg.findGroupIdx(gidx) {
+ if _, ok := existing[gidx]; ok {
groupIdxs = append(groupIdxs, gidx)
}
}
pg.GroupIdxs = groupIdxs
return len(groupIdxs) > 0
}