go-gorm / gorm

The fantastic ORM library for Golang, aims to be developer friendly
https://gorm.io
MIT License
37.02k stars 3.94k forks source link

use map look-up for indexes #7242

Closed abbyssoul closed 1 week ago

abbyssoul commented 1 month ago

What did this pull request do?

Changing the implementation of schema.LookIndex to use map's two-value assignment tests for the existence of a key when looking for an index before switching to field lookup for performance.

User Case Description

The existing implementation of Schema.LookIndex uses linear search (in the best case) instead of using map test using const-time before falling back to a linear scan. The new implementation has a performance advantage for cases with many indexes.