How to handle the slow query in SQL
As you find challenges in writing or maintaining databases, especially for SQL Server, here I found something that I either forget or don’t realise.
Challenge
Facing this query that always returns more than 1 minute to run. I am checking about the index and I didn’t see anything significant.
Solution
When you join the table, ensure the data type between the 2 tables is the same. In my case, I had a fact table that has millions of records and join with the reference table. One is using INT data type and the other one is using BIGINT data type. I’ve changed the reference one to INT instead.
Credits
Photo by Manuel Geissinger: https://www.pexels.com/photo/black-server-racks-on-a-room-325229/
[Note: Pageviews – 3,396 – before migrated from the Dewalist Blog website on 09/08/2020]