I have a simple search query in a table with 2 million records SELECT"products"."id","products"."active","products"."title","products"."subtitle","products"."description","products"."isbn","products"."ean","products"."bznr","products"."cover_picture","products"."publication_date","products"."edition","products"."publisher","products"."stock","products"."delivery_time","products"."selling_price","products"."width","products"."height","products"."length","products"."weight" FROM "products" WHERE products.title ILIKE '%19 Hearts: Courting Deception%' ORDER BY title asc LIMIT 10 (GORM generated query) the query in code : res := dbHandler. Scopes(query.Paginate(listRequest)). Where(where.Main, where.Values...). Order(orderBy). Find(rows)
I'm using an index on title to make search faster, the problem is that when i put this query 5 times in a row without any other traffic it executes a few times in 20 ms and then just goes and executes for 4-5s, when i do the request RAW it then works perfectly. So i'm wondering what is happening and why is it slowing down like that? What i also realised is when i do a search that returns more products it works perfectly all the time without slowing down, but when the search returns 1-3 products it then works perfectly and after 3-4 querys it slows down to like 5 seconds.
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: a631807682
The currently tracked time is not the actual execution time of SQL, but the time returned by the complete API, including the blocking of debugging breakpoints and the time superposition caused by nested execution. We are currently discussing how to change it.
move to https://github.com/go-gorm/gorm/issues/6292