GORM's Association Joins Generate the Wasteful Query Developers Feared Writing by Hand
The author previously hand-wrote an unnecessary join and now tests whether GORM's own generated SQL is any more efficient. They compared three ways of fetching orders from Pune-based users in GORM: association joins, a hand-written join string, and a subquery. The association-join version produced the same redundant join through users to addresses, selected every column, and was the slowest, roughly twice as slow when limited to one CPU core. The other two approaches avoided the users table entirely. The benchmark used 5 million rows in each of users, addresses and orders on PostgreSQL 16, with the code and setup available in a GitHub repository.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in