Skip to content

Commit b117ce6

Browse files
committed
mv to one loop pk applier
1 parent d98e142 commit b117ce6

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

sql/analyzer/resolve_create_select.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,38 +39,26 @@ func resolveCreateSelect(ctx *sql.Context, a *Analyzer, n sql.Node, scope *plan.
3939
}
4040

4141
// Apply primary key constraints from index definitions to the merged schema
42-
pkOrdinals := make([]int, 0)
4342
var nonPkIndexes sql.IndexDefs
4443
for _, idx := range ct.Indexes() {
4544
if idx.IsPrimary() {
4645
for _, idxCol := range idx.Columns {
4746
for i, schCol := range newSch {
4847
if schCol.Name == idxCol.Name {
4948
newSch[i].PrimaryKey = true
50-
pkOrdinals = append(pkOrdinals, i)
5149
break
5250
}
5351
}
5452
}
5553
} else {
56-
// Keep non-primary key indexes
5754
nonPkIndexes = append(nonPkIndexes, idx)
5855
}
5956
}
60-
61-
// Also check for columns already marked as primary key
57+
58+
pkOrdinals := make([]int, 0)
6259
for i, col := range newSch {
6360
if col.PrimaryKey {
64-
found := false
65-
for _, pk := range pkOrdinals {
66-
if pk == i {
67-
found = true
68-
break
69-
}
70-
}
71-
if !found {
72-
pkOrdinals = append(pkOrdinals, i)
73-
}
61+
pkOrdinals = append(pkOrdinals, i)
7462
}
7563
}
7664

0 commit comments

Comments
 (0)